In [1]:
%cd /Users/zinengmao/GWU/DNSC_6314
/Users/zinengmao/GWU/DNSC_6314
In [2]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import seaborn as sns
from sklearn.linear_model import LinearRegression, Ridge, RidgeCV, Lasso, LassoCV
from sklearn.preprocessing import scale 
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
from sklearn.metrics import r2_score
In [3]:
# read csv files
df_Feb=pd.read_csv('202302-captialbikeshare-tripdata.csv') # Note: a different file name
df_Mar=pd.read_csv('202303-capitalbikeshare-tripdata.csv')
df_Apr=pd.read_csv('202304-capitalbikeshare-tripdata.csv')
df_May=pd.read_csv('202305-capitalbikeshare-tripdata.csv')
df_Jun=pd.read_csv('202306-capitalbikeshare-tripdata.csv')
In [4]:
# concat data
df=pd.concat([df_Feb,df_Mar,df_Apr,df_May,df_Jun])
df.info()
<class 'pandas.core.frame.DataFrame'>
Index: 1749886 entries, 0 to 430669
Data columns (total 13 columns):
 #   Column              Dtype  
---  ------              -----  
 0   ride_id             object 
 1   rideable_type       object 
 2   started_at          object 
 3   ended_at            object 
 4   start_station_name  object 
 5   start_station_id    float64
 6   end_station_name    object 
 7   end_station_id      float64
 8   start_lat           float64
 9   start_lng           float64
 10  end_lat             float64
 11  end_lng             float64
 12  member_casual       object 
dtypes: float64(6), object(7)
memory usage: 186.9+ MB
In [5]:
df.head()
Out[5]:
ride_id rideable_type started_at ended_at start_station_name start_station_id end_station_name end_station_id start_lat start_lng end_lat end_lng member_casual
0 6D7F3F3DDD864A41 classic_bike 2023-02-04 21:08:26 2023-02-04 21:16:39 New Jersey Ave & N St NW/Dunbar HS 31636.0 8th & V St NW 31134.0 38.907333 -77.015360 38.917716 -77.022684 member
1 1B4FD92511BA8869 classic_bike 2023-02-28 18:24:01 2023-02-28 18:28:46 11th & Girard St NW 31126.0 8th & V St NW 31134.0 38.925636 -77.027112 38.917716 -77.022684 member
2 E215D5A904EC376F classic_bike 2023-02-12 14:03:48 2023-02-12 14:05:44 3rd & H St NW 31604.0 1st & H St NW 31638.0 38.899408 -77.015289 38.900358 -77.012108 member
3 AF176FEC3204AEB5 classic_bike 2023-02-08 19:25:13 2023-02-08 19:33:08 7th St & Florida Ave NW 31109.0 7th & F St NW / National Portrait Gallery 31232.0 38.916137 -77.022003 38.897283 -77.022191 member
4 CB8BE52EB8F58E80 classic_bike 2023-02-27 14:48:59 2023-02-27 14:54:10 8th & V St NW 31134.0 8th & V St NW 31134.0 38.917716 -77.022684 38.917716 -77.022684 member
In [6]:
# Transform time to date ONLY
df['started_at_date'] = pd.to_datetime(df['started_at']).dt.date
df['ended_at_date'] = pd.to_datetime(df['ended_at']).dt.date
In [7]:
df.head()
Out[7]:
ride_id rideable_type started_at ended_at start_station_name start_station_id end_station_name end_station_id start_lat start_lng end_lat end_lng member_casual started_at_date ended_at_date
0 6D7F3F3DDD864A41 classic_bike 2023-02-04 21:08:26 2023-02-04 21:16:39 New Jersey Ave & N St NW/Dunbar HS 31636.0 8th & V St NW 31134.0 38.907333 -77.015360 38.917716 -77.022684 member 2023-02-04 2023-02-04
1 1B4FD92511BA8869 classic_bike 2023-02-28 18:24:01 2023-02-28 18:28:46 11th & Girard St NW 31126.0 8th & V St NW 31134.0 38.925636 -77.027112 38.917716 -77.022684 member 2023-02-28 2023-02-28
2 E215D5A904EC376F classic_bike 2023-02-12 14:03:48 2023-02-12 14:05:44 3rd & H St NW 31604.0 1st & H St NW 31638.0 38.899408 -77.015289 38.900358 -77.012108 member 2023-02-12 2023-02-12
3 AF176FEC3204AEB5 classic_bike 2023-02-08 19:25:13 2023-02-08 19:33:08 7th St & Florida Ave NW 31109.0 7th & F St NW / National Portrait Gallery 31232.0 38.916137 -77.022003 38.897283 -77.022191 member 2023-02-08 2023-02-08
4 CB8BE52EB8F58E80 classic_bike 2023-02-27 14:48:59 2023-02-27 14:54:10 8th & V St NW 31134.0 8th & V St NW 31134.0 38.917716 -77.022684 38.917716 -77.022684 member 2023-02-27 2023-02-27
In [8]:
# Group and get pickup occurrence for 22nd & H St NW
df_sub1 = df[df['start_station_name']=="22nd & H St NW"]
df_grp1 = df_sub1.groupby(['started_at_date','start_station_name']).size()
df_pu=df_grp1.reset_index(name = "pu_ct")
df_pu
Out[8]:
started_at_date start_station_name pu_ct
0 2023-02-01 22nd & H St NW 20
1 2023-02-02 22nd & H St NW 26
2 2023-02-03 22nd & H St NW 14
3 2023-02-04 22nd & H St NW 12
4 2023-02-05 22nd & H St NW 17
... ... ... ...
145 2023-06-26 22nd & H St NW 21
146 2023-06-27 22nd & H St NW 20
147 2023-06-28 22nd & H St NW 26
148 2023-06-29 22nd & H St NW 32
149 2023-06-30 22nd & H St NW 29

150 rows × 3 columns

In [9]:
# Group and get drop off occurrence for 22nd & H St NW
df_sub2 = df[df['end_station_name']=="22nd & H St NW"]
df_grp2 = df_sub2.groupby(['ended_at_date','end_station_name']).size()
df_do=df_grp2.reset_index(name = "do_ct")
df_do
Out[9]:
ended_at_date end_station_name do_ct
0 2023-02-01 22nd & H St NW 24
1 2023-02-02 22nd & H St NW 28
2 2023-02-03 22nd & H St NW 17
3 2023-02-04 22nd & H St NW 13
4 2023-02-05 22nd & H St NW 24
... ... ... ...
145 2023-06-26 22nd & H St NW 18
146 2023-06-27 22nd & H St NW 21
147 2023-06-28 22nd & H St NW 26
148 2023-06-29 22nd & H St NW 43
149 2023-06-30 22nd & H St NW 21

150 rows × 3 columns

In [10]:
fig, ax1 = plt.subplots(figsize=(12, 9))
ax1.plot_date( df_pu['started_at_date'], df_pu['pu_ct'],linestyle = 'solid',markeredgecolor = 'blue',markerfacecolor = 'blue', markersize = 3)
ax1.plot_date( df_do['ended_at_date'], df_do['do_ct'],linestyle = 'solid',markeredgecolor = 'red',markerfacecolor = 'red', markersize = 3)

ax1.set_xlabel('Date',fontsize=10)
ax1.set_ylabel('Count',fontsize=16)
plt.gcf().autofmt_xdate()

plt.tick_params(labelsize=18)
plt.show()  
No description has been provided for this image
In [11]:
df_weather = pd.read_csv('washington, dc 2023-01-01 to 2023-12-31.csv')

df_weather.head()
Out[11]:
name datetime tempmax tempmin temp feelslikemax feelslikemin feelslike dew humidity ... solarenergy uvindex severerisk sunrise sunset moonphase conditions description icon stations
0 washington, dc 2023-01-01 61.4 43.5 51.8 61.4 41.7 51.2 46.2 82.2 ... 8.7 4 10 2023-01-01T07:26:52 2023-01-01T16:56:42 0.32 Rain, Partially cloudy Clearing in the afternoon with morning rain. rain KDCA,72405013743,72403793728,KADW,KDAA,AS365,7...
1 washington, dc 2023-01-02 63.0 40.0 50.9 63.0 36.3 50.2 44.2 79.3 ... 5.7 4 10 2023-01-02T07:26:59 2023-01-02T16:57:31 0.35 Partially cloudy Partly cloudy throughout the day. partly-cloudy-day KDCA,72405013743,72403793728,KADW,KDAA,AS365,7...
2 washington, dc 2023-01-03 68.0 50.1 59.3 68.0 50.1 59.3 52.3 78.5 ... 3.4 2 10 2023-01-03T07:27:04 2023-01-03T16:58:22 0.39 Overcast Cloudy skies throughout the day. cloudy KDCA,72405013743,72403793728,KADW,KDAA,AS365,7...
3 washington, dc 2023-01-04 65.0 53.3 59.5 65.0 53.3 59.5 55.0 85.4 ... 2.8 2 10 2023-01-04T07:27:07 2023-01-04T16:59:14 0.42 Partially cloudy Partly cloudy throughout the day. partly-cloudy-day KDCA,72405013743,72403793728,KADW,KDAA,AS365,7...
4 washington, dc 2023-01-05 64.0 49.6 56.4 64.0 45.1 55.9 46.0 70.4 ... 6.0 4 10 2023-01-05T07:27:08 2023-01-05T17:00:08 0.46 Partially cloudy Partly cloudy throughout the day. partly-cloudy-day KDCA,72405013743,72403793728,KADW,KDAA,AS365,7...

5 rows × 33 columns

In [12]:
import plotly.figure_factory as ff
from plotly.offline import iplot
import numpy as np
numeric_df_sub1 = df_sub1.select_dtypes(include=[np.number])
corrs=numeric_df_sub1.corr()
# Plotting Heatmap to know about Correlation
figure=ff.create_annotated_heatmap(z=corrs.values,x=list(corrs.columns),
    y=list(corrs.index),
    annotation_text=corrs.round(2).values,
    showscale=True)
figure.layout.margin = dict(l=200, t=200)
figure.layout.height = 800
figure.layout.width = 1000
iplot(figure)
In [13]:
# Date time format 
df_weather['datetime'] = pd.to_datetime(df_weather['datetime']).dt.date

# Use sns heatmap to see whats are the null values.
coln = df_weather.columns[:df_weather.shape[1]]  
colors = ['#000099','#ffff00'] # specify the colors - yellow is missing. blue is not missing.
sns.heatmap(df_weather[coln].isnull(), cmap = sns.color_palette(colors))
plt.show()
No description has been provided for this image
In [14]:
# Drop unnecessary variables
df_weather=df_weather.drop(columns=['name', 'stations','description','sunrise','sunset','conditions','severerisk','preciptype','windgust'])
In [15]:
# Merge with weather data and remove dates and station name
# pickup data
df_merge = df_pu.merge(df_do, left_on='started_at_date', right_on='ended_at_date') 
In [16]:
df_merge.head()
Out[16]:
started_at_date start_station_name pu_ct ended_at_date end_station_name do_ct
0 2023-02-01 22nd & H St NW 20 2023-02-01 22nd & H St NW 24
1 2023-02-02 22nd & H St NW 26 2023-02-02 22nd & H St NW 28
2 2023-02-03 22nd & H St NW 14 2023-02-03 22nd & H St NW 17
3 2023-02-04 22nd & H St NW 12 2023-02-04 22nd & H St NW 13
4 2023-02-05 22nd & H St NW 17 2023-02-05 22nd & H St NW 24
In [17]:
# Merge with weather data and remove dates and station name
# pickup data
df_merge = df_merge.merge(df_weather, left_on='started_at_date', right_on='datetime') 
df_merge = df_merge.drop(columns=['started_at_date','start_station_name','datetime'])
In [18]:
df_merge.head()
Out[18]:
pu_ct ended_at_date end_station_name do_ct tempmax tempmin temp feelslikemax feelslikemin feelslike ... windspeed winddir sealevelpressure cloudcover visibility solarradiation solarenergy uvindex moonphase icon
0 20 2023-02-01 22nd & H St NW 24 40.7 32.5 35.6 37.4 23.9 29.1 ... 15.3 347.8 1025.5 81.8 9.1 130.3 11.2 6 0.36 snow
1 26 2023-02-02 22nd & H St NW 28 41.8 31.3 36.0 36.8 28.1 32.2 ... 11.3 199.9 1021.8 94.5 9.9 87.7 7.5 4 0.40 cloudy
2 14 2023-02-03 22nd & H St NW 17 40.7 19.8 31.7 34.1 4.3 20.7 ... 28.1 317.1 1021.4 54.6 9.9 143.9 12.5 6 0.43 partly-cloudy-day
3 12 2023-02-04 22nd & H St NW 13 31.9 16.9 24.5 23.0 2.6 15.1 ... 16.9 221.9 1035.2 27.8 9.9 150.7 13.1 6 0.46 partly-cloudy-day
4 17 2023-02-05 22nd & H St NW 24 58.8 33.0 44.2 58.8 22.9 39.9 ... 17.9 195.8 1022.1 79.7 9.9 116.1 9.9 5 0.50 partly-cloudy-day

5 rows × 27 columns

In [19]:
df_merge.columns
Out[19]:
Index(['pu_ct', 'ended_at_date', 'end_station_name', 'do_ct', 'tempmax',
       'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew',
       'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'snowdepth',
       'windspeed', 'winddir', 'sealevelpressure', 'cloudcover', 'visibility',
       'solarradiation', 'solarenergy', 'uvindex', 'moonphase', 'icon'],
      dtype='object')
In [20]:
# Merge with weather data and remove dates and station name
# pickup data
df_m_pu = df_pu.merge(df_weather, left_on='started_at_date', right_on='datetime') 
df_m_pu = df_m_pu.drop(columns=['started_at_date','start_station_name','datetime'])

# dropoff data
df_m_do = df_do.merge(df_weather, left_on='ended_at_date', right_on='datetime') 
df_m_do = df_m_do.drop(columns=['ended_at_date','end_station_name','datetime'])
In [21]:
sns.pairplot(df_m_pu, vars=['temp', 'dew', 'humidity', 'precip','snow', 'windspeed', 'visibility'], hue='pu_ct')
plt.show()
/Users/zinengmao/anaconda3/lib/python3.11/site-packages/seaborn/_oldcore.py:1119: FutureWarning:

use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instead.

/Users/zinengmao/anaconda3/lib/python3.11/site-packages/seaborn/_oldcore.py:1119: FutureWarning:

use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instead.

/Users/zinengmao/anaconda3/lib/python3.11/site-packages/seaborn/_oldcore.py:1119: FutureWarning:

use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instead.

/Users/zinengmao/anaconda3/lib/python3.11/site-packages/seaborn/_oldcore.py:1119: FutureWarning:

use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instead.

/Users/zinengmao/anaconda3/lib/python3.11/site-packages/seaborn/_oldcore.py:1119: FutureWarning:

use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instead.

/Users/zinengmao/anaconda3/lib/python3.11/site-packages/seaborn/_oldcore.py:1119: FutureWarning:

use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instead.

/Users/zinengmao/anaconda3/lib/python3.11/site-packages/seaborn/_oldcore.py:1119: FutureWarning:

use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instead.

No description has been provided for this image
In [22]:
sns.pairplot(df_m_do, vars=['temp', 'dew', 'humidity', 'precip','snow', 'windspeed', 'visibility'], hue='do_ct')
plt.show()
/Users/zinengmao/anaconda3/lib/python3.11/site-packages/seaborn/_oldcore.py:1119: FutureWarning:

use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instead.

/Users/zinengmao/anaconda3/lib/python3.11/site-packages/seaborn/_oldcore.py:1119: FutureWarning:

use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instead.

/Users/zinengmao/anaconda3/lib/python3.11/site-packages/seaborn/_oldcore.py:1119: FutureWarning:

use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instead.

/Users/zinengmao/anaconda3/lib/python3.11/site-packages/seaborn/_oldcore.py:1119: FutureWarning:

use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instead.

/Users/zinengmao/anaconda3/lib/python3.11/site-packages/seaborn/_oldcore.py:1119: FutureWarning:

use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instead.

/Users/zinengmao/anaconda3/lib/python3.11/site-packages/seaborn/_oldcore.py:1119: FutureWarning:

use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instead.

/Users/zinengmao/anaconda3/lib/python3.11/site-packages/seaborn/_oldcore.py:1119: FutureWarning:

use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instead.

No description has been provided for this image
In [23]:
weather_features = ['temp', 'dew', 'humidity', 'precip','snow', 'windspeed', 'visibility']


plt.figure(figsize=(16, 10))

for i, feature in enumerate(weather_features):
    plt.subplot(2, 4, i+1)
    plt.scatter(df_m_pu[feature], df_m_pu['pu_ct'])
    plt.title(f'Pick_ups vs. {feature}')
    plt.xlabel(feature)
    plt.ylabel('Pick_ups')

plt.tight_layout()
plt.show()
No description has been provided for this image
In [24]:
weather_features = ['temp', 'dew', 'humidity', 'precip','snow', 'windspeed', 'visibility']


plt.figure(figsize=(16, 10))

for i, feature in enumerate(weather_features):
    plt.subplot(2, 4, i+1)
    plt.scatter(df_m_pu[feature], df_m_do ['do_ct'])
    plt.title(f'drop_off vs. {feature}')
    plt.xlabel(feature)
    plt.ylabel('drop_offs')

plt.tight_layout()
plt.show()
No description has been provided for this image
In [25]:
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error

Model Comparsion - Pickup¶

In [26]:
import itertools
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
from sklearn.linear_model import LinearRegression, Ridge, Lasso, ElasticNet
from sklearn.neighbors import KNeighborsRegressor
import warnings
warnings.simplefilter(action='ignore', category=UserWarning)
warnings.simplefilter(action='ignore', category=FutureWarning)

# Your dataset
df = df_merge.drop(columns=['ended_at_date', 'end_station_name'])  # Rename the dataset to df for convenience
df = pd.get_dummies(data=df, drop_first=True)

y = df['pu_ct']

# Define your models here
models = {
    'Linear Regression': LinearRegression(),
    'Ridge Regression': Ridge(),
    'LASSO': Lasso(),
    'Elastic Net': ElasticNet(),
    'KNN Regressor': KNeighborsRegressor()
}

# Function to train and evaluate a model
def train_and_evaluate(model, X_train, X_test, y_train, y_test):
    model.fit(X_train, y_train)
    predictions = model.predict(X_test)
    mse = mean_squared_error(y_test, predictions)
    return mse

# List of features
features = ['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin',
       'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover',
       'snow', 'windspeed', 'winddir', 'sealevelpressure', 'cloudcover',
       'visibility', 'solarradiation', 'solarenergy', 'uvindex', 'moonphase',
       'icon_cloudy', 'icon_partly-cloudy-day', 'icon_rain', 'icon_snow']

# Initialize a list to keep track of MSE and features used
model_performance = []

# Start with an empty list of features to use and add one feature at a time
for i in range(1, len(features) + 1):
    current_features = features[:i]
    X = df[current_features]
    
    # Splitting the dataset for training and testing
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.6, random_state=200)
    
    # Record performance for each model with the current set of features
    for name, model in models.items():
        mse = train_and_evaluate(model, X_train, X_test, y_train, y_test)
        model_performance.append({
            'Model': name,
            'MSE': mse,
            'Features': ', '.join(current_features)  # Store the features used as a string
        })

# Convert the list of model performances to a DataFrame for analysis
performance_df_pu = pd.DataFrame(model_performance)
In [27]:
import matplotlib.pyplot as plt
import seaborn as sns


# Plotting
plt.figure(figsize=(10, 8))

# Since the DataFrame is sorted, we can plot the MSEs in order.
# We'll use a lineplot here, but you can choose a bar plot if that's more appropriate for your data.
sns.lineplot(data=performance_df_pu, x='Features', y='MSE', hue='Model', marker='o')

# Improve readability
plt.xticks(rotation=45, ha='right')  # Rotate x-axis labels for better readability
plt.xlabel('Features Used')
plt.ylabel('MSE')
plt.title('Model Performance by MSE and Features Used')
plt.legend(title='Model', bbox_to_anchor=(1.05, 1), loc='upper left')  # Move the legend out of the plot
plt.tight_layout()  # Adjust layout so everything fits without overlapping

# Show the plot
plt.show()
No description has been provided for this image
In [28]:
# the MSE for each model with the corresponding features used
# Sort the DataFrame by 'Model' first, then 'MSE', so that the lowest MSE is at the top for each model
performance_df_pu_sorted = performance_df_pu.sort_values(by=['Model', 'MSE'])

# Drop duplicates, keeping only the first entry for each model, which is the entry with the lowest MSE
lowest_mse_per_model_pu = performance_df_pu_sorted.drop_duplicates(subset='Model')

# Set display options to show the full content of 'Features' column
pd.set_option('display.max_colwidth', None)

# Display the DataFrame with the lowest MSE for each model
print(lowest_mse_per_model_pu)
                Model        MSE  \
68        Elastic Net  62.600098   
9       KNN Regressor  85.728444   
67              LASSO  62.976665   
65  Linear Regression  63.265892   
66   Ridge Regression  59.984724   

                                                                                                                                   Features  
68  tempmax, tempmin, temp, feelslikemax, feelslikemin, feelslike, dew, humidity, precip, precipprob, precipcover, snow, windspeed, winddir  
9                                                                                                                          tempmax, tempmin  
67  tempmax, tempmin, temp, feelslikemax, feelslikemin, feelslike, dew, humidity, precip, precipprob, precipcover, snow, windspeed, winddir  
65  tempmax, tempmin, temp, feelslikemax, feelslikemin, feelslike, dew, humidity, precip, precipprob, precipcover, snow, windspeed, winddir  
66  tempmax, tempmin, temp, feelslikemax, feelslikemin, feelslike, dew, humidity, precip, precipprob, precipcover, snow, windspeed, winddir  
In [29]:
# the MSE for each model with the corresponding features used
# Sort the DataFrame by MSE in ascending order
performance_df_pu_sorted = performance_df_pu.sort_values('MSE')
performance_df_pu_sorted.head(1)
Out[29]:
Model MSE Features
66 Ridge Regression 59.984724 tempmax, tempmin, temp, feelslikemax, feelslikemin, feelslike, dew, humidity, precip, precipprob, precipcover, snow, windspeed, winddir

Model Comparsion - Dropoff¶

In [30]:
import itertools
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
from sklearn.linear_model import LinearRegression, Ridge, Lasso, ElasticNet
from sklearn.neighbors import KNeighborsRegressor
import warnings
warnings.simplefilter(action='ignore', category=UserWarning)
warnings.simplefilter(action='ignore', category=FutureWarning)

# Your dataset
df = df_merge.drop(columns=['ended_at_date', 'end_station_name'])  # Rename the dataset to df for convenience
df = pd.get_dummies(data=df, drop_first=True)

y = df['do_ct']

# Define your models here
models = {
    'Linear Regression': LinearRegression(),
    'Ridge Regression': Ridge(),
    'LASSO': Lasso(),
    'Elastic Net': ElasticNet(),
    'KNN Regressor': KNeighborsRegressor()
}

# Function to train and evaluate a model
def train_and_evaluate(model, X_train, X_test, y_train, y_test):
    model.fit(X_train, y_train)
    predictions = model.predict(X_test)
    mse = mean_squared_error(y_test, predictions)
    return mse

# List of features
features = ['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin',
       'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover',
       'snow', 'windspeed', 'winddir', 'sealevelpressure', 'cloudcover',
       'visibility', 'solarradiation', 'solarenergy', 'uvindex', 'moonphase',
       'icon_cloudy', 'icon_partly-cloudy-day', 'icon_rain', 'icon_snow']

# Initialize a list to keep track of MSE and features used
model_performance = []

# Start with an empty list of features to use and add one feature at a time
for i in range(1, len(features) + 1):
    current_features = features[:i]
    X = df[current_features]
    
    # Splitting the dataset for training and testing
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.6, random_state=200)
    
    # Record performance for each model with the current set of features
    for name, model in models.items():
        mse = train_and_evaluate(model, X_train, X_test, y_train, y_test)
        model_performance.append({
            'Model': name,
            'MSE': mse,
            'Features': ', '.join(current_features)  # Store the features used as a string
        })

# Convert the list of model performances to a DataFrame for analysis
performance_df_do = pd.DataFrame(model_performance)
In [31]:
import matplotlib.pyplot as plt
import seaborn as sns


# Plotting
plt.figure(figsize=(10, 8))

# Since the DataFrame is sorted, we can plot the MSEs in order.
# We'll use a lineplot here, but you can choose a bar plot if that's more appropriate for your data.
sns.lineplot(data=performance_df_do, x='Features', y='MSE', hue='Model', marker='o')

# Improve readability
plt.xticks(rotation=45, ha='right')  # Rotate x-axis labels for better readability
plt.xlabel('Features Used')
plt.ylabel('MSE')
plt.title('Model Performance by MSE and Features Used')
plt.legend(title='Model', bbox_to_anchor=(1.05, 1), loc='upper left')  # Move the legend out of the plot
plt.tight_layout()  # Adjust layout so everything fits without overlapping

# Show the plot
plt.show()
No description has been provided for this image
In [32]:
# the MSE for each model with the corresponding features used
# Sort the DataFrame by 'Model' first, then 'MSE', so that the lowest MSE is at the top for each model
performance_df_do_sorted = performance_df_do.sort_values(by=['Model', 'MSE'])

# Drop duplicates, keeping only the first entry for each model, which is the entry with the lowest MSE
lowest_mse_per_model_do = performance_df_do_sorted.drop_duplicates(subset='Model')

# Set display options to show the full content of 'Features' column
pd.set_option('display.max_colwidth', None)

# Display the DataFrame with the lowest MSE for each model
print(lowest_mse_per_model_do)
                Model        MSE  \
53        Elastic Net  68.244185   
64      KNN Regressor  84.013778   
52              LASSO  68.310409   
35  Linear Regression  68.426862   
41   Ridge Regression  65.593919   

                                                                                                                          Features  
53                   tempmax, tempmin, temp, feelslikemax, feelslikemin, feelslike, dew, humidity, precip, precipprob, precipcover  
64  tempmax, tempmin, temp, feelslikemax, feelslikemin, feelslike, dew, humidity, precip, precipprob, precipcover, snow, windspeed  
52                   tempmax, tempmin, temp, feelslikemax, feelslikemin, feelslike, dew, humidity, precip, precipprob, precipcover  
35                                                    tempmax, tempmin, temp, feelslikemax, feelslikemin, feelslike, dew, humidity  
41                                            tempmax, tempmin, temp, feelslikemax, feelslikemin, feelslike, dew, humidity, precip  
In [33]:
# the MSE for each model with the corresponding features used
# Sort the DataFrame by MSE in ascending order
performance_df_do_sorted = performance_df_do.sort_values('MSE')
performance_df_do_sorted.head(1)
Out[33]:
Model MSE Features
41 Ridge Regression 65.593919 tempmax, tempmin, temp, feelslikemax, feelslikemin, feelslike, dew, humidity, precip
In [34]:
# team agrees on using same set of x feature to evaluate different modelings

Linear Regression - Pickup¶

In [35]:
# Splitting the dataset for training and testing
X = df_merge.drop(columns=['pu_ct'])
y = df_merge['pu_ct']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.6, random_state=200)
In [36]:
Model_linear = LinearRegression()
Model_linear.fit(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']], y_train) 
Out[36]:
LinearRegression()
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
LinearRegression()
In [37]:
print(pd.Series(Model_linear.coef_.flatten(), index=X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']].columns))
tempmax          1.974751
tempmin          0.722858
temp            -7.231890
feelslikemax    -0.300938
feelslikemin    -0.341258
feelslike        3.622103
dew              1.281771
humidity        -0.562580
precip         -14.966812
precipprob      -0.055412
precipcover      0.012891
snow            18.659574
windspeed        0.098502
winddir          0.016617
dtype: float64
In [38]:
y_pred = Model_linear.predict(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']])
mse_train_6 = round(mean_squared_error(y_train, y_pred),3)
print(f"MSE in training data is {mse_train_6}")
r2 = r2_score(y_train, y_pred)
print(f"Co-efficient of determination {r2}")
MSE in training data is 51.954
Co-efficient of determination 0.48157304287152425
In [39]:
y_pred = Model_linear.predict(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']])
mse_test_6 = round(mean_squared_error(y_test, y_pred),3)
print(f"MSE in test data is {mse_test_6}")
r2 = r2_score(y_test, y_pred)
print(f"Co-efficient of determination {r2}")
MSE in test data is 63.266
Co-efficient of determination 0.4445433771403927
In [40]:
# Create a DataFrame with predictions and actual outcomes
df_predictions = pd.DataFrame({
    'y_pred_pu': y_pred,
    'y_test_pu': y_test
}).reset_index(drop=True)  # reset_index to ensure we can sample correctly

# Sample 50 random rows from the DataFrame
df_sampled_pu = df_predictions.sample(n=50, random_state=42)  # Use a fixed random state for reproducibility

# df_sampled is now a DataFrame with 50 random rows of predictions and actual values for the specified model
print(df_sampled_pu)
    y_pred_pu  y_test_pu
40  15.612549         11
22  25.034796         40
55  30.978623         32
70   9.141763         10
0   29.009442         36
26  28.283651         30
39  -0.971444          8
65  31.312496         33
10  30.613361         38
44  23.973516         18
81   9.366483          9
35  35.505312         44
56  30.864969         34
86  44.776399         50
12  23.138230         21
4   26.267536         30
18  34.157425         39
28  12.360872         28
49  18.857801         20
62  31.865113         19
73  28.255884         33
69  16.866261         11
76  20.152027         29
30  10.992007          7
33  33.568843         17
11  10.364319         14
66  24.793393         33
67  12.641162          9
31  32.426058         42
75  28.247929         40
9   31.270452         27
68  33.450589         15
5   26.078425         21
42  19.599743         28
47  26.895016         18
16  34.519274         34
45  29.385372         22
34  16.565732         22
7   28.614136         35
78  26.382081         21
27  29.875039         25
19  22.822666         13
84  53.469721         41
25  32.830454         23
53  31.655778         29
13  25.606005         10
24  29.105558         18
3    7.836946         14
17   7.816984         10
38  24.629304         32

Linear Regression - Dropoff¶

In [41]:
# Splitting the dataset for training and testing
X = df_merge.drop(columns=['do_ct'])
y = df_merge['do_ct']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.6, random_state=200)
In [42]:
Model_linear1 = LinearRegression()
Model_linear1.fit(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']], y_train) 
Out[42]:
LinearRegression()
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
LinearRegression()
In [43]:
print(pd.Series(Model_linear1.coef_.flatten(), index=X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']].columns))
tempmax         3.094465
tempmin         1.258804
temp           -8.523579
feelslikemax   -1.637131
feelslikemin   -0.579084
feelslike       4.353292
dew             1.998095
humidity       -1.163305
dtype: float64
In [44]:
y_pred = Model_linear1.predict(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']])
mse_train_6 = round(mean_squared_error(y_train, y_pred),3)
print(f"MSE in training data is {mse_train_6}")
r2 = r2_score(y_train, y_pred)
print(f"Co-efficient of determination {r2}")
MSE in training data is 68.027
Co-efficient of determination 0.36147096833485637
In [45]:
y_pred = Model_linear1.predict(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']])
mse_test_6 = round(mean_squared_error(y_test, y_pred),3)
print(f"MSE in test data is {mse_test_6}")
r2 = r2_score(y_test, y_pred)
print(f"Co-efficient of determination {r2}")
MSE in test data is 68.427
Co-efficient of determination 0.38071501396647967
In [46]:
# Create a DataFrame with predictions and actual outcomes
df_predictions = pd.DataFrame({
    'y_pred_do': y_pred,
    'y_test_do': y_test
}).reset_index(drop=True)  # reset_index to ensure we can sample correctly

# Sample 50 random rows from the DataFrame
df_sampled_do = df_predictions.sample(n=50, random_state=42)  # Use a fixed random state for reproducibility

# df_sampled is now a DataFrame with 50 random rows of predictions and actual values for the specified model
print(df_sampled_do)
    y_pred_do  y_test_do
40  17.758932         12
22  27.803595         39
55  27.716403         33
70  13.948523         13
0   32.555900         42
26  28.748938         27
39  14.759747          8
65  28.930176         26
10  28.257808         41
44  30.580490         24
81  11.882144         12
35  32.779625         36
56  31.019083         38
86  41.961685         48
12  18.881042         33
4   33.458166         33
18  32.067846         38
28  13.877144         22
49  22.383634         31
62  35.224384         22
73  34.133000         32
69  21.998918         16
76  24.905728         21
30  12.460753          9
33  31.490240         24
11   8.525682         17
66  29.566897         33
67  19.381958          4
31  29.065391         42
75  36.055250         33
9   27.893197         27
68  32.086561         12
5   29.931795         20
42  28.310991         31
47  18.097978         20
16  29.927992         31
45  31.349786         17
34  26.301674         17
7   30.954838         35
78  21.886804         21
27  29.242779         35
19  28.995703         16
84  48.127226         41
25  29.180472         15
53  32.983156         29
13  33.130030         10
24  27.619922         27
3   12.874517         15
17  13.458290         10
38  30.830481         30

Decision Performance Evaluation¶

In [47]:
combined_df = df_sampled_pu.join(df_sampled_do, lsuffix='_pu', rsuffix='_do')

# Rename columns as necessary
combined_df.columns = ['y_pred_pu', 'y_test_pu', 'y_pred_do', 'y_test_do']

# Now combined_df has the required columns
print(combined_df)
    y_pred_pu  y_test_pu  y_pred_do  y_test_do
40  15.612549         11  17.758932         12
22  25.034796         40  27.803595         39
55  30.978623         32  27.716403         33
70   9.141763         10  13.948523         13
0   29.009442         36  32.555900         42
26  28.283651         30  28.748938         27
39  -0.971444          8  14.759747          8
65  31.312496         33  28.930176         26
10  30.613361         38  28.257808         41
44  23.973516         18  30.580490         24
81   9.366483          9  11.882144         12
35  35.505312         44  32.779625         36
56  30.864969         34  31.019083         38
86  44.776399         50  41.961685         48
12  23.138230         21  18.881042         33
4   26.267536         30  33.458166         33
18  34.157425         39  32.067846         38
28  12.360872         28  13.877144         22
49  18.857801         20  22.383634         31
62  31.865113         19  35.224384         22
73  28.255884         33  34.133000         32
69  16.866261         11  21.998918         16
76  20.152027         29  24.905728         21
30  10.992007          7  12.460753          9
33  33.568843         17  31.490240         24
11  10.364319         14   8.525682         17
66  24.793393         33  29.566897         33
67  12.641162          9  19.381958          4
31  32.426058         42  29.065391         42
75  28.247929         40  36.055250         33
9   31.270452         27  27.893197         27
68  33.450589         15  32.086561         12
5   26.078425         21  29.931795         20
42  19.599743         28  28.310991         31
47  26.895016         18  18.097978         20
16  34.519274         34  29.927992         31
45  29.385372         22  31.349786         17
34  16.565732         22  26.301674         17
7   28.614136         35  30.954838         35
78  26.382081         21  21.886804         21
27  29.875039         25  29.242779         35
19  22.822666         13  28.995703         16
84  53.469721         41  48.127226         41
25  32.830454         23  29.180472         15
53  31.655778         29  32.983156         29
13  25.606005         10  33.130030         10
24  29.105558         18  27.619922         27
3    7.836946         14  12.874517         15
17   7.816984         10  13.458290         10
38  24.629304         32  30.830481         30
In [48]:
from gurobipy import Model, GRB
from gurobipy import max_

# Define penalties
penalty_pu = 2000000.0000005
penalty_do = 2000000

# Create empty lists to store the results of optimization
optimal_x_values = []
optimal_y_values = []
optimal_objective_values = []

# Loop over the rows in the combined_df DataFrame
for index, row in combined_df.iterrows():
    # Create a new model for each iteration
    m = Model("optimization")

    # Extract the y_pred_pu and y_pred_do values for the current iteration
    y_pred_pu = row['y_pred_pu']
    y_pred_do = row['y_pred_do']

    # Create variables
    x = m.addVar(vtype=GRB.CONTINUOUS, name="x", lb=0)
    y = m.addVar(vtype=GRB.CONTINUOUS, name="y", lb=0)

    # Create auxiliary variables for the max expressions
    max_diff_do = m.addVar(vtype=GRB.CONTINUOUS, name="max_diff_do")
    max_diff_pu = m.addVar(vtype=GRB.CONTINUOUS, name="max_diff_pu")

    # Set objective
    m.setObjective(penalty_do * max_diff_do + penalty_pu * max_diff_pu, GRB.MINIMIZE)

    # Add constraint: x + y = 17 (Example constraint, adjust as needed)
    m.addConstr(x + y == 17, "constraint_sum")
    
    # Add constraints to ensure the auxiliary variables are at least 0 and at least the differences
    m.addConstr(max_diff_do >= 0, "max_diff_do_positive")
    m.addConstr(max_diff_do >= y_pred_do - x, "max_diff_do_y_pred_do")

    m.addConstr(max_diff_pu >= 0, "max_diff_pu_positive")
    m.addConstr(max_diff_pu >= y_pred_pu - y, "max_diff_pu_y_pred_pu")

    # Optimize model
    m.optimize()

    # Store the results
    optimal_x_values.append(x.X)
    optimal_y_values.append(y.X)
    optimal_objective_values.append(m.objVal)

# Add the optimization results to combined_df
combined_df['optimal_x'] = optimal_x_values
combined_df['optimal_y'] = optimal_y_values
combined_df['optimal_objective'] = optimal_objective_values

# Now combined_df includes the optimization results
print(combined_df)
Set parameter Username
Academic license - for non-commercial use only - expires 2025-01-23
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x8876c445
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 4 rows and 2 columns
Presolve time: 0.00s
Presolved: 1 rows, 2 columns, 2 nonzeros

Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.5178648e+06   7.806275e+00   0.000000e+00      0s
       1    3.2742963e+07   0.000000e+00   0.000000e+00      0s

Solved in 1 iterations and 0.00 seconds (0.00 work units)
Optimal objective  3.274296323e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x98035c37
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.1676781e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.167678104e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x91c5fc96
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.3390051e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.339005100e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xd4fc9e56
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [9e+00, 2e+01]
Presolve removed 3 rows and 1 columns
Presolve time: 0.00s
Presolved: 2 rows, 3 columns, 4 nonzeros

Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    0.0000000e+00   4.570882e+00   0.000000e+00      0s
       2    1.2180572e+07   0.000000e+00   0.000000e+00      0s

Solved in 2 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.218057238e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xfff46f9a
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.9130685e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.913068525e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x4a182d33
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.0065177e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.006517733e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x8b198c74
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [1e+00, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    0.0000000e+00   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  0.000000000e+00
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x4ce41e29
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.6485343e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.648534254e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xd00e0e19
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.3742338e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.374233847e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x0302aa8b
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.5108013e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.510801270e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xd146139d
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [9e+00, 2e+01]
Presolve removed 3 rows and 1 columns
Presolve time: 0.00s
Presolved: 2 rows, 3 columns, 4 nonzeros

Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    0.0000000e+00   4.683241e+00   0.000000e+00      0s
       2    8.4972531e+06   0.000000e+00   0.000000e+00      0s

Solved in 2 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.497253067e+06
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x5e94c886
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.0256987e+08   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.025698743e+08
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x6b4ba0e1
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.9768105e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.976810507e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xae8cf7c0
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.3947617e+08   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.394761676e+08
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x50ce0cfb
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    5.0038544e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  5.003854353e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x8efd0c06
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.5451405e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.545140485e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xde2e47da
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.8450541e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.845054110e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xd4fcaf94
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [1e+01, 2e+01]
Presolve removed 3 rows and 1 columns
Presolve time: 0.00s
Presolved: 2 rows, 3 columns, 4 nonzeros

Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    0.0000000e+00   6.180436e+00   0.000000e+00      0s
       2    1.8476032e+07   0.000000e+00   0.000000e+00      0s

Solved in 2 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.847603221e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x0215cf40
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    4.8482869e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  4.848286950e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xd126d3fb
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.0017899e+08   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.001789943e+08
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x769e40b6
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.0777768e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.077776847e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x86bd1aa5
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 4 rows and 2 columns
Presolve time: 0.00s
Presolved: 1 rows, 2 columns, 2 nonzeros

Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.9978363e+06   8.433130e+00   0.000000e+00      0s
       1    4.3730358e+07   0.000000e+00   0.000000e+00      0s

Solved in 1 iterations and 0.00 seconds (0.00 work units)
Optimal objective  4.373035762e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x1fd2b485
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    5.6115510e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  5.611551035e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xd7ce88d7
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [1e+01, 2e+01]
Presolve removed 3 rows and 1 columns
Presolve time: 0.00s
Presolved: 2 rows, 3 columns, 4 nonzeros

Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    0.0000000e+00   5.496003e+00   0.000000e+00      0s
       2    1.2905520e+07   0.000000e+00   0.000000e+00      0s

Solved in 2 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.290551978e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xc560ced9
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.6118167e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.611816668e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x88f124bb
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [9e+00, 2e+01]
Presolve removed 3 rows and 1 columns
Presolve time: 0.00s
Presolved: 2 rows, 3 columns, 4 nonzeros

Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    0.0000000e+00   5.182160e+00   0.000000e+00      0s
       2    3.7800030e+06   0.000000e+00   0.000000e+00      0s

Solved in 2 iterations and 0.00 seconds (0.00 work units)
Optimal objective  3.780003031e+06
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x4970f18e
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.4720580e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.472058045e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x11315043
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [1e+01, 2e+01]
Presolve removed 4 rows and 2 columns
Presolve time: 0.00s
Presolved: 1 rows, 2 columns, 2 nonzeros

Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    4.7639156e+06   6.320581e+00   0.000000e+00      0s
       1    3.0046240e+07   0.000000e+00   0.000000e+00      0s

Solved in 1 iterations and 0.00 seconds (0.00 work units)
Optimal objective  3.004624041e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x364278de
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.8982897e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.898289659e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xff143143
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.4606359e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.460635868e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x1a2c04e1
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.4327298e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.432729755e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xe4c80c25
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.7074302e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.707430185e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x8c362f8e
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.8020439e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.802043940e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x503b187d
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.1821467e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.182146698e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x1f7607b6
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    5.5985988e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  5.598598775e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xa218e96e
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.4894532e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.489453238e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x60cd12ae
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.7470317e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.747031666e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xc44bbec4
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 4 rows and 2 columns
Presolve time: 0.07s
Presolved: 1 rows, 2 columns, 2 nonzeros

Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.8603347e+07   8.282866e+00   0.000000e+00      0s
       1    5.1734810e+07   0.000000e+00   0.000000e+00      0s

Solved in 1 iterations and 0.07 seconds (0.00 work units)
Optimal objective  5.173481005e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x68f7f027
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.5137950e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.513794983e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xf8a90e69
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.2537771e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.253777060e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x818a7e9c
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.4235635e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.423563542e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x2fd31849
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.9636738e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.963673783e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x418729ae
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 5e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.6919390e+08   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.691938951e+08
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x95de7150
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.0021853e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.002185348e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x104d013d
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.5277868e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.527786802e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x5b012df3
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.3472070e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.347206975e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xf4cc6854
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.9450959e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.945095905e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xa2be51b1
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [8e+00, 2e+01]
Presolve removed 3 rows and 1 columns
Presolve time: 0.00s
Presolved: 2 rows, 3 columns, 4 nonzeros

Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    0.0000000e+00   3.918473e+00   0.000000e+00      0s
       2    7.4229244e+06   0.000000e+00   0.000000e+00      0s

Solved in 2 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.422924446e+06
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x2ca4ab10
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [8e+00, 2e+01]
Presolve removed 3 rows and 1 columns
Presolve time: 0.00s
Presolved: 2 rows, 3 columns, 4 nonzeros

Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    0.0000000e+00   3.908492e+00   0.000000e+00      0s
       2    8.5505482e+06   0.000000e+00   0.000000e+00      0s

Solved in 2 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.550548237e+06
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x56ca9328
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.6919569e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.691956887e+07
    y_pred_pu  y_test_pu  y_pred_do  y_test_do  optimal_x  optimal_y  \
40  15.612549         11  17.758932         12   1.387451  15.612549   
22  25.034796         40  27.803595         39  17.000000   0.000000   
55  30.978623         32  27.716403         33  17.000000   0.000000   
70   9.141763         10  13.948523         13   7.858237   9.141763   
0   29.009442         36  32.555900         42  17.000000   0.000000   
26  28.283651         30  28.748938         27  17.000000   0.000000   
39  -0.971444          8  14.759747          8  17.000000   0.000000   
65  31.312496         33  28.930176         26  17.000000   0.000000   
10  30.613361         38  28.257808         41  17.000000   0.000000   
44  23.973516         18  30.580490         24  17.000000   0.000000   
81   9.366483          9  11.882144         12   7.633517   9.366483   
35  35.505312         44  32.779625         36  17.000000   0.000000   
56  30.864969         34  31.019083         38  17.000000   0.000000   
86  44.776399         50  41.961685         48  17.000000   0.000000   
12  23.138230         21  18.881042         33  17.000000   0.000000   
4   26.267536         30  33.458166         33  17.000000   0.000000   
18  34.157425         39  32.067846         38  17.000000   0.000000   
28  12.360872         28  13.877144         22   4.639128  12.360872   
49  18.857801         20  22.383634         31  17.000000   0.000000   
62  31.865113         19  35.224384         22  17.000000   0.000000   
73  28.255884         33  34.133000         32  17.000000   0.000000   
69  16.866261         11  21.998918         16   0.133739  16.866261   
76  20.152027         29  24.905728         21  17.000000   0.000000   
30  10.992007          7  12.460753          9   6.007993  10.992007   
33  33.568843         17  31.490240         24  17.000000   0.000000   
11  10.364319         14   8.525682         17   6.635681  10.364319   
66  24.793393         33  29.566897         33  17.000000   0.000000   
67  12.641162          9  19.381958          4   4.358838  12.641162   
31  32.426058         42  29.065391         42  17.000000   0.000000   
75  28.247929         40  36.055250         33  17.000000   0.000000   
9   31.270452         27  27.893197         27  17.000000   0.000000   
68  33.450589         15  32.086561         12  17.000000   0.000000   
5   26.078425         21  29.931795         20  17.000000   0.000000   
42  19.599743         28  28.310991         31  17.000000   0.000000   
47  26.895016         18  18.097978         20  17.000000   0.000000   
16  34.519274         34  29.927992         31  17.000000   0.000000   
45  29.385372         22  31.349786         17  17.000000   0.000000   
34  16.565732         22  26.301674         17   0.434268  16.565732   
7   28.614136         35  30.954838         35  17.000000   0.000000   
78  26.382081         21  21.886804         21  17.000000   0.000000   
27  29.875039         25  29.242779         35  17.000000   0.000000   
19  22.822666         13  28.995703         16  17.000000   0.000000   
84  53.469721         41  48.127226         41  17.000000   0.000000   
25  32.830454         23  29.180472         15  17.000000   0.000000   
53  31.655778         29  32.983156         29  17.000000   0.000000   
13  25.606005         10  33.130030         10  17.000000   0.000000   
24  29.105558         18  27.619922         27  17.000000   0.000000   
3    7.836946         14  12.874517         15   9.163054   7.836946   
17   7.816984         10  13.458290         10   9.183016   7.816984   
38  24.629304         32  30.830481         30  17.000000   0.000000   

    optimal_objective  
40       3.274296e+07  
22       7.167678e+07  
55       8.339005e+07  
70       1.218057e+07  
0        8.913069e+07  
26       8.006518e+07  
39       0.000000e+00  
65       8.648534e+07  
10       8.374234e+07  
44       7.510801e+07  
81       8.497253e+06  
35       1.025699e+08  
56       8.976811e+07  
86       1.394762e+08  
12       5.003854e+07  
4        8.545140e+07  
18       9.845054e+07  
28       1.847603e+07  
49       4.848287e+07  
62       1.001790e+08  
73       9.077777e+07  
69       4.373036e+07  
76       5.611551e+07  
30       1.290552e+07  
33       9.611817e+07  
11       3.780003e+06  
66       7.472058e+07  
67       3.004624e+07  
31       8.898290e+07  
75       9.460636e+07  
9        8.432730e+07  
68       9.707430e+07  
5        7.802044e+07  
42       6.182147e+07  
47       5.598599e+07  
16       9.489453e+07  
45       8.747032e+07  
34       5.173481e+07  
7        8.513795e+07  
78       6.253777e+07  
27       8.423564e+07  
19       6.963674e+07  
84       1.691939e+08  
25       9.002185e+07  
53       9.527787e+07  
13       8.347207e+07  
24       7.945096e+07  
3        7.422924e+06  
17       8.550548e+06  
38       7.691957e+07  
In [49]:
# Define the penalties
penalty_pu = 2000000.0000005
penalty_do = 2000000

# Function to apply the formula
def calculate_penalty(row):
    penalty_for_pu = penalty_pu * max(0, row['y_test_pu'] - row['optimal_y'])
    penalty_for_do = penalty_do * max(0, row['y_test_do'] - row['optimal_x'])
    return penalty_for_pu + penalty_for_do

# Apply the function to each row and create a new column
combined_df['total_out_of_sameple_cost'] = combined_df.apply(calculate_penalty, axis=1)
print(combined_df['total_out_of_sameple_cost'])
40    2.122510e+07
22    1.240000e+08
55    9.600000e+07
70    1.200000e+07
0     1.220000e+08
26    8.000000e+07
39    1.600000e+07
65    8.400000e+07
10    1.240000e+08
44    5.000000e+07
81    8.732966e+06
35    1.260000e+08
56    1.100000e+08
86    1.620000e+08
12    7.400000e+07
4     9.200000e+07
18    1.200000e+08
28    6.600000e+07
49    6.800000e+07
62    4.800000e+07
73    9.600000e+07
69    3.173252e+07
76    6.600000e+07
30    5.984013e+06
33    4.800000e+07
11    2.800000e+07
66    9.800000e+07
67    0.000000e+00
31    1.340000e+08
75    1.120000e+08
9     7.400000e+07
68    3.000000e+07
5     4.800000e+07
42    8.400000e+07
47    4.200000e+07
16    9.600000e+07
45    4.400000e+07
34    4.400000e+07
7     1.060000e+08
78    5.000000e+07
27    8.600000e+07
19    2.600000e+07
84    1.300000e+08
25    4.600000e+07
53    8.200000e+07
13    2.000000e+07
24    5.600000e+07
3     2.400000e+07
17    6.000000e+06
38    9.000000e+07
Name: total_out_of_sameple_cost, dtype: float64
In [50]:
# Calculate the average of the 'total_penalty' column
average_total_out_of_sameple_cost = combined_df['total_out_of_sameple_cost'].mean()

print("Average Total out of sameple cost:", average_total_out_of_sameple_cost)
Average Total out of sameple cost: 68153491.96792553

Ridge - Pickup¶

In [51]:
# Splitting the dataset for training and testing
X = df_merge.drop(columns=['pu_ct'])
y = df_merge['pu_ct']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.6, random_state=200)
In [52]:
alphas = 10**np.linspace(-2,5,100)

ridge = Ridge()
coefs = []

for a in alphas:
    ridge.set_params(alpha=a)
    ridge.fit(scale(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']]), y_train)
    coefs.append(ridge.coef_)

ax = plt.gca()
ax.plot(alphas, coefs)
ax.set_xscale('log')
ax.set_xlim(ax.get_xlim())  
plt.axis('tight')
plt.xlabel('alpha')
plt.ylabel('Coefficients')
plt.legend(list(X.columns), loc='right')

plt.title('Ridge coefficients as a function of the regularization');
No description has been provided for this image
In [53]:
# standardize the features
from sklearn.preprocessing import StandardScaler

scaler = StandardScaler().fit(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']])
In [54]:
# set a large alpha to get smaller coefficients
ridge = Ridge(alpha=1000)
ridge.fit(scaler.transform(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']]), y_train)

print('The coefficients are:')
print(pd.Series(ridge.coef_.flatten(), index=X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']].columns))
The coefficients are:
tempmax         0.103319
tempmin         0.015408
temp            0.062078
feelslikemax    0.099710
feelslikemin    0.040424
feelslike       0.077282
dew            -0.001406
humidity       -0.124935
precip         -0.201112
precipprob     -0.220270
precipcover    -0.206020
snow           -0.043669
windspeed      -0.018511
winddir         0.075207
dtype: float64
In [55]:
# find the best alpha via CV with selected scoring metric
ridgecv = RidgeCV(alphas=alphas, scoring='neg_mean_squared_error')
ridgecv.fit(scale(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']]), y_train)

print('The best alpha from RidgeCV:', ridgecv.alpha_)
The best alpha from RidgeCV: 55.90810182512222
In [56]:
# with the best alpha
ridge.set_params(alpha=ridgecv.alpha_)
ridge.fit(scale(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']]), y_train)
print('The coefficients are:')
print(pd.Series(ridge.coef_.flatten(), index=X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']].columns))
The coefficients are:
tempmax         0.710046
tempmin        -0.461904
temp            0.086123
feelslikemax    0.719945
feelslikemin   -0.111727
feelslike       0.370408
dew             0.002307
humidity       -0.220404
precip         -1.143415
precipprob     -1.235117
precipcover    -1.051164
snow           -0.159105
windspeed      -0.024461
winddir         0.531427
dtype: float64
In [57]:
y_pred = ridgecv.predict(scale(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']]))
r_r_p = r2_score(y_test, y_pred)
print(f"R^2 in pickup test data for Ridge is {r_r_p}")
R^2 in pickup test data for Ridge is 0.2756219424302043
In [58]:
r_m_p = mean_squared_error(y_test, y_pred)
print(f"MSE in pickup test data for Ridge is {r_m_p}")
MSE in pickup test data for Ridge is 82.50585589269132
In [59]:
# Create a DataFrame with predictions and actual outcomes
df_predictions = pd.DataFrame({
    'y_pred_pu': y_pred,
    'y_test_pu': y_test
}).reset_index(drop=True)  # reset_index to ensure we can sample correctly

# Sample 50 random rows from the DataFrame
df_sampled_pu = df_predictions.sample(n=50, random_state=42)  # Use a fixed random state for reproducibility

# df_sampled is now a DataFrame with 50 random rows of predictions and actual values for the specified model
print(df_sampled_pu)
    y_pred_pu  y_test_pu
40  21.015142         11
22  31.110516         40
55  28.811043         32
70  20.418020         10
0   25.787758         36
26  28.042526         30
39  10.650241          8
65  29.991690         33
10  30.992608         38
44  28.686796         18
81  19.226775          9
35  29.075196         44
56  29.394832         34
86  30.646061         50
12  28.367615         21
4   26.526485         30
18  30.562262         39
28  22.796104         28
49  22.237035         20
62  29.936042         19
73  29.451447         33
69  23.600283         11
76  23.673223         29
30  21.865141          7
33  28.590863         17
11  26.993885         14
66  25.279853         33
67  27.213798          9
31  29.803418         42
75  26.131622         40
9   30.321270         27
68  29.439995         15
5   27.223418         21
42  24.068974         28
47  27.400962         18
16  30.048295         34
45  29.386770         22
34  23.683409         22
7   28.641955         35
78  28.468400         21
27  29.222777         25
19  31.567365         13
84  30.143191         41
25  28.510697         23
53  29.011062         29
13  25.480307         10
24  28.105857         18
3   22.250822         14
17  26.615690         10
38  29.237912         32

Ridge - Dropoff¶

In [60]:
# Splitting the dataset for training and testing
X = df_merge.drop(columns=['do_ct'])
y = df_merge['do_ct']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.6, random_state=200)
In [61]:
alphas = 10**np.linspace(-2,5,100)

ridge = Ridge()
coefs = []

for a in alphas:
    ridge.set_params(alpha=a)
    ridge.fit(scale(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']]), y_train)
    coefs.append(ridge.coef_)

ax = plt.gca()
ax.plot(alphas, coefs)
ax.set_xscale('log')
ax.set_xlim(ax.get_xlim())  
plt.axis('tight')
plt.xlabel('alpha')
plt.ylabel('Coefficients')
plt.legend(list(X.columns), loc='best')

plt.title('Ridge coefficients as a function of the regularization');
No description has been provided for this image
In [62]:
# standardize the features
from sklearn.preprocessing import StandardScaler

scaler = StandardScaler().fit(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']])
In [63]:
# set a large alpha to get smaller coefficients
ridge = Ridge(alpha=1000)
ridge.fit(scaler.transform(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']]), y_train)

print('The coefficients are:')
print(pd.Series(ridge.coef_.flatten(), index=X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']].columns))
The coefficients are:
tempmax         0.149782
tempmin         0.073784
temp            0.115320
feelslikemax    0.136854
feelslikemin    0.097467
feelslike       0.128594
dew             0.046129
humidity       -0.117748
dtype: float64
In [64]:
# find the best alpha via CV with selected scoring metric
ridgecv = RidgeCV(alphas=alphas, scoring='neg_mean_squared_error')
ridgecv.fit(scale(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']]), y_train)

print('The best alpha from RidgeCV:', ridgecv.alpha_)
The best alpha from RidgeCV: 0.019179102616724886
In [65]:
# with the best alpha
ridge.set_params(alpha=ridgecv.alpha_)
ridge.fit(scale(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']]), y_train)
print('The coefficients are:')
print(pd.Series(ridge.coef_.flatten(), index=X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']].columns))
The coefficients are:
tempmax         30.415517
tempmin          5.637341
temp           -75.331935
feelslikemax   -16.651522
feelslikemin    -2.166443
feelslike       44.710447
dew             21.107038
humidity       -11.987350
dtype: float64
In [66]:
y_pred = ridgecv.predict(scale(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']]))
r_r_d = r2_score(y_test, y_pred)
print(f"R^2 in drop off test data for Ridge is {r_r_d}")
R^2 in drop off test data for Ridge is 0.3054804665187536
In [67]:
r_m_d = mean_squared_error(y_test, ridgecv.predict(scale(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']])))
print(f"MSE in drop off test data for Ridge is {r_m_d}")
MSE in drop off test data for Ridge is 76.7397783194545
In [68]:
# Create a DataFrame with predictions and actual outcomes
df_predictions = pd.DataFrame({
    'y_pred_do': y_pred,
    'y_test_do': y_test
}).reset_index(drop=True)  # reset_index to ensure we can sample correctly

# Sample 50 random rows from the DataFrame
df_sampled_do = df_predictions.sample(n=50, random_state=42)  # Use a fixed random state for reproducibility

# df_sampled is now a DataFrame with 50 random rows of predictions and actual values for the specified model
print(df_sampled_do)
    y_pred_do  y_test_do
40  22.124270         12
22  27.249943         39
55  29.891917         33
70  21.068640         13
0   34.447423         42
26  29.417921         27
39  20.979799          8
65  29.869238         26
10  28.757563         41
44  30.349825         24
81  18.684817         12
35  35.170075         36
56  31.699907         38
86  40.555240         48
12  22.125159         33
4   32.874566         33
18  31.609511         38
28  18.968300         22
49  26.240347         31
62  34.411061         22
73  33.269070         32
69  24.215663         16
76  25.153983         21
30  20.871625          9
33  32.627311         24
11  16.033150         17
66  30.946841         33
67  23.152440          4
31  30.781885         42
75  35.712116         33
9   28.836417         27
68  33.760240         12
5   30.215128         20
42  30.535370         31
47  24.517768         20
16  31.772067         31
45  31.798535         17
34  28.027689         17
7   32.316638         35
78  25.668729         21
27  30.415292         35
19  27.645700         16
84  45.666520         41
25  31.824631         15
53  33.898364         29
13  33.162088         10
24  31.722192         27
3   20.449996         15
17  18.477708         10
38  30.114591         30

Decision Performance Evaluation¶

In [69]:
combined_df = df_sampled_pu.join(df_sampled_do, lsuffix='_pu', rsuffix='_do')

# Rename columns as necessary
combined_df.columns = ['y_pred_pu', 'y_test_pu', 'y_pred_do', 'y_test_do']

# Now combined_df has the required columns
print(combined_df)
    y_pred_pu  y_test_pu  y_pred_do  y_test_do
40  21.015142         11  22.124270         12
22  31.110516         40  27.249943         39
55  28.811043         32  29.891917         33
70  20.418020         10  21.068640         13
0   25.787758         36  34.447423         42
26  28.042526         30  29.417921         27
39  10.650241          8  20.979799          8
65  29.991690         33  29.869238         26
10  30.992608         38  28.757563         41
44  28.686796         18  30.349825         24
81  19.226775          9  18.684817         12
35  29.075196         44  35.170075         36
56  29.394832         34  31.699907         38
86  30.646061         50  40.555240         48
12  28.367615         21  22.125159         33
4   26.526485         30  32.874566         33
18  30.562262         39  31.609511         38
28  22.796104         28  18.968300         22
49  22.237035         20  26.240347         31
62  29.936042         19  34.411061         22
73  29.451447         33  33.269070         32
69  23.600283         11  24.215663         16
76  23.673223         29  25.153983         21
30  21.865141          7  20.871625          9
33  28.590863         17  32.627311         24
11  26.993885         14  16.033150         17
66  25.279853         33  30.946841         33
67  27.213798          9  23.152440          4
31  29.803418         42  30.781885         42
75  26.131622         40  35.712116         33
9   30.321270         27  28.836417         27
68  29.439995         15  33.760240         12
5   27.223418         21  30.215128         20
42  24.068974         28  30.535370         31
47  27.400962         18  24.517768         20
16  30.048295         34  31.772067         31
45  29.386770         22  31.798535         17
34  23.683409         22  28.027689         17
7   28.641955         35  32.316638         35
78  28.468400         21  25.668729         21
27  29.222777         25  30.415292         35
19  31.567365         13  27.645700         16
84  30.143191         41  45.666520         41
25  28.510697         23  31.824631         15
53  29.011062         29  33.898364         29
13  25.480307         10  33.162088         10
24  28.105857         18  31.722192         27
3   22.250822         14  20.449996         15
17  26.615690         10  18.477708         10
38  29.237912         32  30.114591         30
In [70]:
from gurobipy import Model, GRB
from gurobipy import max_

# Define penalties
penalty_pu = 2000000.0000005
penalty_do = 2000000

# Create empty lists to store the results of optimization
optimal_x_values = []
optimal_y_values = []
optimal_objective_values = []

# Loop over the rows in the combined_df DataFrame
for index, row in combined_df.iterrows():
    # Create a new model for each iteration
    m = Model("optimization")

    # Extract the y_pred_pu and y_pred_do values for the current iteration
    y_pred_pu = row['y_pred_pu']
    y_pred_do = row['y_pred_do']

    # Create variables
    x = m.addVar(vtype=GRB.CONTINUOUS, name="x", lb=0)
    y = m.addVar(vtype=GRB.CONTINUOUS, name="y", lb=0)

    # Create auxiliary variables for the max expressions
    max_diff_do = m.addVar(vtype=GRB.CONTINUOUS, name="max_diff_do")
    max_diff_pu = m.addVar(vtype=GRB.CONTINUOUS, name="max_diff_pu")

    # Set objective
    m.setObjective(penalty_do * max_diff_do + penalty_pu * max_diff_pu, GRB.MINIMIZE)

    # Add constraint: x + y = 17 (Example constraint, adjust as needed)
    m.addConstr(x + y == 17, "constraint_sum")
    
    # Add constraints to ensure the auxiliary variables are at least 0 and at least the differences
    m.addConstr(max_diff_do >= 0, "max_diff_do_positive")
    m.addConstr(max_diff_do >= y_pred_do - x, "max_diff_do_y_pred_do")

    m.addConstr(max_diff_pu >= 0, "max_diff_pu_positive")
    m.addConstr(max_diff_pu >= y_pred_pu - y, "max_diff_pu_y_pred_pu")

    # Optimize model
    m.optimize()

    # Store the results
    optimal_x_values.append(x.X)
    optimal_y_values.append(y.X)
    optimal_objective_values.append(m.objVal)

# Add the optimization results to combined_df
combined_df['optimal_x'] = optimal_x_values
combined_df['optimal_y'] = optimal_y_values
combined_df['optimal_objective'] = optimal_objective_values

# Now combined_df includes the optimization results
print(combined_df)
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xf9314277
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    5.2278825e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  5.227882493e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x585eb833
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.2720917e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.272091697e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xc63fd08b
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.3405919e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.340591889e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x95dc4cdb
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    4.8973320e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  4.897332024e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xcc5c6a61
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.6470363e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.647036288e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x4063d7fa
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.0920893e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.092089317e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x36f1133b
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [1e+01, 2e+01]
Presolve removed 4 rows and 2 columns
Presolve time: 0.00s
Presolved: 1 rows, 2 columns, 2 nonzeros

Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.9595979e+06   5.325121e+00   0.000000e+00      0s
       1    2.9260080e+07   0.000000e+00   0.000000e+00      0s

Solved in 1 iterations and 0.00 seconds (0.00 work units)
Optimal objective  2.926007998e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x0eebabdb
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.5721856e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.572185587e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x73abf7bf
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.5500343e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.550034329e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x0181f721
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.4073243e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.407324300e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x89aa7701
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    4.1823184e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  4.182318379e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x5e0041db
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.4490543e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.449054289e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x771d20e2
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.8189478e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.818947788e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xcdef99a5
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.0840260e+08   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.084026017e+08
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x6f096d81
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.6985549e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.698554878e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xb4ee91f5
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.4802101e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.480210054e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x8d2591a7
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.0343546e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.034354558e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x0688f780
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    4.9528808e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  4.952880838e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xcaa1a2c1
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.2954764e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.295476444e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xe92c5dba
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.4694207e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.469420688e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xef4af62d
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.1441033e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.144103342e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x39c4b415
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.1631891e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.163189146e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x82341450
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.3654411e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.365441148e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x6fd41e71
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    5.1473533e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  5.147353278e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x95aea885
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.8436348e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.843634751e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xc4c50f6d
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    5.2054070e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  5.205407038e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xea8dfb61
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.8453389e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.845338864e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x428dd884
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.6732476e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.673247633e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x21f168b3
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.7170606e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.717060635e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x8d90df4e
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.9687476e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.968747598e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x402ab419
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.4315375e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.431537507e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x40814e9a
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.2400469e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.240046926e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x5a482f09
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.06s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.0877092e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.06 seconds (0.00 work units)
Optimal objective  8.087709234e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xc319d23c
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.5208687e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.520868738e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x9237cfac
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.9837461e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.983746094e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xb9a8ab74
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.9640724e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.01 seconds (0.00 work units)
Optimal objective  8.964072409e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x8d629743
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.8370610e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.01 seconds (0.00 work units)
Optimal objective  8.837061000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xd5ef84e2
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.01s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.9422195e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.01 seconds (0.00 work units)
Optimal objective  6.942219455e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xafbae82a
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.01s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.7917186e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.01 seconds (0.00 work units)
Optimal objective  8.791718598e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xcbe952b8
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.01s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.4274258e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.02 seconds (0.00 work units)
Optimal objective  7.427425842e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x621b13ef
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.01s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.5276137e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.01 seconds (0.00 work units)
Optimal objective  8.527613663e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x57fc8b14
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.4426129e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.442612941e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x3e86670c
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 5e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.1761942e+08   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.176194221e+08
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x3a4d7d91
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.6670655e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.667065516e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xe1b5226d
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.1818852e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.181885162e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xd5bdf7b4
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.3284790e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.328478993e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x7e1afa0e
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.5656098e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.565609825e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x76be37d4
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    5.1401635e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  5.140163535e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xef177d05
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    5.6186798e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  5.618679752e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x67800155
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.4705006e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.470500638e+07
    y_pred_pu  y_test_pu  y_pred_do  y_test_do  optimal_x  optimal_y  \
40  21.015142         11  22.124270         12  17.000000   0.000000   
22  31.110516         40  27.249943         39  17.000000   0.000000   
55  28.811043         32  29.891917         33  17.000000   0.000000   
70  20.418020         10  21.068640         13  17.000000   0.000000   
0   25.787758         36  34.447423         42  17.000000   0.000000   
26  28.042526         30  29.417921         27  17.000000   0.000000   
39  10.650241          8  20.979799          8   6.349759  10.650241   
65  29.991690         33  29.869238         26  17.000000   0.000000   
10  30.992608         38  28.757563         41  17.000000   0.000000   
44  28.686796         18  30.349825         24  17.000000   0.000000   
81  19.226775          9  18.684817         12  17.000000   0.000000   
35  29.075196         44  35.170075         36  17.000000   0.000000   
56  29.394832         34  31.699907         38  17.000000   0.000000   
86  30.646061         50  40.555240         48  17.000000   0.000000   
12  28.367615         21  22.125159         33  17.000000   0.000000   
4   26.526485         30  32.874566         33  17.000000   0.000000   
18  30.562262         39  31.609511         38  17.000000   0.000000   
28  22.796104         28  18.968300         22  17.000000   0.000000   
49  22.237035         20  26.240347         31  17.000000   0.000000   
62  29.936042         19  34.411061         22  17.000000   0.000000   
73  29.451447         33  33.269070         32  17.000000   0.000000   
69  23.600283         11  24.215663         16  17.000000   0.000000   
76  23.673223         29  25.153983         21  17.000000   0.000000   
30  21.865141          7  20.871625          9  17.000000   0.000000   
33  28.590863         17  32.627311         24  17.000000   0.000000   
11  26.993885         14  16.033150         17   0.000000  17.000000   
66  25.279853         33  30.946841         33  17.000000   0.000000   
67  27.213798          9  23.152440          4  17.000000   0.000000   
31  29.803418         42  30.781885         42  17.000000   0.000000   
75  26.131622         40  35.712116         33  17.000000   0.000000   
9   30.321270         27  28.836417         27  17.000000   0.000000   
68  29.439995         15  33.760240         12  17.000000   0.000000   
5   27.223418         21  30.215128         20  17.000000   0.000000   
42  24.068974         28  30.535370         31  17.000000   0.000000   
47  27.400962         18  24.517768         20  17.000000   0.000000   
16  30.048295         34  31.772067         31  17.000000   0.000000   
45  29.386770         22  31.798535         17  17.000000   0.000000   
34  23.683409         22  28.027689         17  17.000000   0.000000   
7   28.641955         35  32.316638         35  17.000000   0.000000   
78  28.468400         21  25.668729         21  17.000000   0.000000   
27  29.222777         25  30.415292         35  17.000000   0.000000   
19  31.567365         13  27.645700         16  17.000000   0.000000   
84  30.143191         41  45.666520         41  17.000000   0.000000   
25  28.510697         23  31.824631         15  17.000000   0.000000   
53  29.011062         29  33.898364         29  17.000000   0.000000   
13  25.480307         10  33.162088         10  17.000000   0.000000   
24  28.105857         18  31.722192         27  17.000000   0.000000   
3   22.250822         14  20.449996         15  17.000000   0.000000   
17  26.615690         10  18.477708         10  17.000000   0.000000   
38  29.237912         32  30.114591         30  17.000000   0.000000   

    optimal_objective  
40       5.227882e+07  
22       8.272092e+07  
55       8.340592e+07  
70       4.897332e+07  
0        8.647036e+07  
26       8.092089e+07  
39       2.926008e+07  
65       8.572186e+07  
10       8.550034e+07  
44       8.407324e+07  
81       4.182318e+07  
35       9.449054e+07  
56       8.818948e+07  
86       1.084026e+08  
12       6.698555e+07  
4        8.480210e+07  
18       9.034355e+07  
28       4.952881e+07  
49       6.295476e+07  
62       9.469421e+07  
73       9.144103e+07  
69       6.163189e+07  
76       6.365441e+07  
30       5.147353e+07  
33       8.843635e+07  
11       5.205407e+07  
66       7.845339e+07  
67       6.673248e+07  
31       8.717061e+07  
75       8.968748e+07  
9        8.431538e+07  
68       9.240047e+07  
5        8.087709e+07  
42       7.520869e+07  
47       6.983746e+07  
16       8.964072e+07  
45       8.837061e+07  
34       6.942219e+07  
7        8.791719e+07  
78       7.427426e+07  
27       8.527614e+07  
19       8.442613e+07  
84       1.176194e+08  
25       8.667066e+07  
53       9.181885e+07  
13       8.328479e+07  
24       8.565610e+07  
3        5.140164e+07  
17       5.618680e+07  
38       8.470501e+07  
In [71]:
# Define the penalties
penalty_pu = 2000000.0000005
penalty_do = 2000000

# Function to apply the formula
def calculate_penalty(row):
    penalty_for_pu = penalty_pu * max(0, row['y_test_pu'] - row['optimal_y'])
    penalty_for_do = penalty_do * max(0, row['y_test_do'] - row['optimal_x'])
    return penalty_for_pu + penalty_for_do

# Apply the function to each row and create a new column
combined_df['total_out_of_sameple_cost'] = combined_df.apply(calculate_penalty, axis=1)

# Calculate the average of the 'total_penalty' column
average_total_out_of_sameple_cost = combined_df['total_out_of_sameple_cost'].mean()

print("Average Total out of sameple cost:", average_total_out_of_sameple_cost)
Average Total out of sameple cost: 69066009.6409148

Lasso - Pickup¶

In [72]:
# Splitting the dataset for training and testing
X = df_merge.drop(columns=['pu_ct'])
y = df_merge['pu_ct']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.6, random_state=200)
In [73]:
alphas = 10**np.linspace(-2,5,100)

lasso = Lasso()
coefs = []

for a in alphas:
    lasso.set_params(alpha=a)
    lasso.fit(scale(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']]), y_train)
    coefs.append(lasso.coef_)

ax = plt.gca()
ax.plot(alphas, coefs)
ax.set_xscale('log')
ax.set_xlim(ax.get_xlim())  
plt.axis('tight')
plt.xlabel('alpha')
plt.ylabel('Coefficients')
plt.legend(list(X.columns), loc='right')

plt.title('Lasso coefficients as a function of the regularization');
No description has been provided for this image
In [74]:
# find the best alpha via CV with selected scoring metric
lassocv = LassoCV(alphas=alphas)
lassocv.fit(scale(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']]), y_train)

print('The best alpha from LassoCV:', lassocv.alpha_)
The best alpha from LassoCV: 1.5556761439304723
In [75]:
# with the best alpha
lasso.set_params(alpha=lassocv.alpha_)
lasso.fit(scale(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']]), y_train)
print('The coefficients are:')
print(pd.Series(lasso.coef_.flatten(), index=X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']].columns))
The coefficients are:
tempmax         0.000000
tempmin         0.000000
temp            0.000000
feelslikemax    0.199025
feelslikemin    0.000000
feelslike       0.000000
dew             0.000000
humidity       -0.000000
precip         -0.857777
precipprob     -1.855704
precipcover    -0.548769
snow           -0.000000
windspeed       0.000000
winddir         0.000000
dtype: float64
In [76]:
plt.semilogx(lassocv.alphas_, lassocv.mse_path_, linestyle=":")
plt.plot(
    lassocv.alphas_,
    lassocv.mse_path_.mean(axis=-1),
    color="black",
    label="Average across the folds",
    linewidth=2,
)
plt.axvline(lassocv.alpha_, linestyle="--", color="black", label="alpha: CV estimate")


plt.xlabel(r"$\alpha$")
plt.ylabel("Mean square error")
plt.legend()
plt.title("MSE")
plt.show()
No description has been provided for this image
In [77]:
l_r_p = r2_score(y_test, lassocv.predict(scale(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']])))
print(f"R^2 in pickup test data for Lasso is: {l_r_p}")
R^2 in pickup test data for Lasso is: 0.1478334150504408
In [78]:
#test data mse
l_m_p = mean_squared_error(y_test, lassocv.predict(scale(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']])))
print(f"MSE in pickup test data for Lasso is {l_m_p}")
MSE in pickup test data for Lasso is 97.06082717399373
In [79]:
# Create a DataFrame with predictions and actual outcomes
df_predictions = pd.DataFrame({
    'y_pred_pu': y_pred,
    'y_test_pu': y_test
}).reset_index(drop=True)  # reset_index to ensure we can sample correctly

# Sample 50 random rows from the DataFrame
df_sampled_pu = df_predictions.sample(n=50, random_state=42)  # Use a fixed random state for reproducibility

# df_sampled is now a DataFrame with 50 random rows of predictions and actual values for the specified model
print(df_sampled_pu)
    y_pred_pu  y_test_pu
40  22.124270         11
22  27.249943         40
55  29.891917         32
70  21.068640         10
0   34.447423         36
26  29.417921         30
39  20.979799          8
65  29.869238         33
10  28.757563         38
44  30.349825         18
81  18.684817          9
35  35.170075         44
56  31.699907         34
86  40.555240         50
12  22.125159         21
4   32.874566         30
18  31.609511         39
28  18.968300         28
49  26.240347         20
62  34.411061         19
73  33.269070         33
69  24.215663         11
76  25.153983         29
30  20.871625          7
33  32.627311         17
11  16.033150         14
66  30.946841         33
67  23.152440          9
31  30.781885         42
75  35.712116         40
9   28.836417         27
68  33.760240         15
5   30.215128         21
42  30.535370         28
47  24.517768         18
16  31.772067         34
45  31.798535         22
34  28.027689         22
7   32.316638         35
78  25.668729         21
27  30.415292         25
19  27.645700         13
84  45.666520         41
25  31.824631         23
53  33.898364         29
13  33.162088         10
24  31.722192         18
3   20.449996         14
17  18.477708         10
38  30.114591         32

LASSO - Dropoff¶

In [80]:
# Splitting the dataset for training and testing
X = df_merge.drop(columns=['do_ct'])
y = df_merge['do_ct']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.6, random_state=200)
In [81]:
alphas = 10**np.linspace(-2,5,100)

lasso = Lasso()
coefs = []

for a in alphas:
    lasso.set_params(alpha=a)
    lasso.fit(scale(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']]), y_train)
    coefs.append(lasso.coef_)

ax = plt.gca()
ax.plot(alphas, coefs)
ax.set_xscale('log')
ax.set_xlim(ax.get_xlim())  
plt.axis('tight')
plt.xlabel('alpha')
plt.ylabel('Coefficients')
plt.legend(list(X.columns), loc='best')

plt.title('Lasso coefficients as a function of the regularization');
No description has been provided for this image
In [82]:
# find the best alpha via CV with selected scoring metric
lassocv = LassoCV(alphas=alphas)
lassocv.fit(scale(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']]), y_train)

print('The best alpha from LassoCV:', lassocv.alpha_)
The best alpha from LassoCV: 0.5857020818056664
In [83]:
# with the best alpha
lasso.set_params(alpha=lassocv.alpha_)
lasso.fit(scale(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']]), y_train)
print('The coefficients are:')
print(pd.Series(lasso.coef_.flatten(), index=X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']].columns))
The coefficients are:
tempmax         2.841152
tempmin        -0.000000
temp            0.000000
feelslikemax    0.000000
feelslikemin    0.000000
feelslike       0.000000
dew            -0.000000
humidity       -1.713310
dtype: float64
In [84]:
plt.semilogx(lassocv.alphas_, lassocv.mse_path_, linestyle=":")
plt.plot(
    lassocv.alphas_,
    lassocv.mse_path_.mean(axis=-1),
    color="black",
    label="Average across the folds",
    linewidth=2,
)
plt.axvline(lassocv.alpha_, linestyle="--", color="black", label="alpha: CV estimate")


plt.xlabel(r"$\alpha$")
plt.ylabel("Mean square error")
plt.legend()
plt.title("MSE")
plt.show()
No description has been provided for this image
In [85]:
l_r_d = r2_score(y_test, lassocv.predict(scale(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']])))
print(f"R^2 in drop off test data for Lasso is: {l_r_d}")
R^2 in drop off test data for Lasso is: 0.21467805229593462
In [86]:
#test data mse
l_m_d = mean_squared_error(y_test, lassocv.predict(scale(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']])))
print(f"MSE in drop off test data for Lasso is {l_m_d}")
MSE in drop off test data for Lasso is 86.77283974164784
In [87]:
# Create a DataFrame with predictions and actual outcomes
df_predictions = pd.DataFrame({
    'y_pred_do': y_pred,
    'y_test_do': y_test
}).reset_index(drop=True)  # reset_index to ensure we can sample correctly

# Sample 50 random rows from the DataFrame
df_sampled_do = df_predictions.sample(n=50, random_state=42)  # Use a fixed random state for reproducibility

# df_sampled is now a DataFrame with 50 random rows of predictions and actual values for the specified model
print(df_sampled_do)
    y_pred_do  y_test_do
40  22.124270         12
22  27.249943         39
55  29.891917         33
70  21.068640         13
0   34.447423         42
26  29.417921         27
39  20.979799          8
65  29.869238         26
10  28.757563         41
44  30.349825         24
81  18.684817         12
35  35.170075         36
56  31.699907         38
86  40.555240         48
12  22.125159         33
4   32.874566         33
18  31.609511         38
28  18.968300         22
49  26.240347         31
62  34.411061         22
73  33.269070         32
69  24.215663         16
76  25.153983         21
30  20.871625          9
33  32.627311         24
11  16.033150         17
66  30.946841         33
67  23.152440          4
31  30.781885         42
75  35.712116         33
9   28.836417         27
68  33.760240         12
5   30.215128         20
42  30.535370         31
47  24.517768         20
16  31.772067         31
45  31.798535         17
34  28.027689         17
7   32.316638         35
78  25.668729         21
27  30.415292         35
19  27.645700         16
84  45.666520         41
25  31.824631         15
53  33.898364         29
13  33.162088         10
24  31.722192         27
3   20.449996         15
17  18.477708         10
38  30.114591         30

Decision Performance Evaluation¶

In [88]:
combined_df = df_sampled_pu.join(df_sampled_do, lsuffix='_pu', rsuffix='_do')

# Rename columns as necessary
combined_df.columns = ['y_pred_pu', 'y_test_pu', 'y_pred_do', 'y_test_do']

# Now combined_df has the required columns
print(combined_df)
    y_pred_pu  y_test_pu  y_pred_do  y_test_do
40  22.124270         11  22.124270         12
22  27.249943         40  27.249943         39
55  29.891917         32  29.891917         33
70  21.068640         10  21.068640         13
0   34.447423         36  34.447423         42
26  29.417921         30  29.417921         27
39  20.979799          8  20.979799          8
65  29.869238         33  29.869238         26
10  28.757563         38  28.757563         41
44  30.349825         18  30.349825         24
81  18.684817          9  18.684817         12
35  35.170075         44  35.170075         36
56  31.699907         34  31.699907         38
86  40.555240         50  40.555240         48
12  22.125159         21  22.125159         33
4   32.874566         30  32.874566         33
18  31.609511         39  31.609511         38
28  18.968300         28  18.968300         22
49  26.240347         20  26.240347         31
62  34.411061         19  34.411061         22
73  33.269070         33  33.269070         32
69  24.215663         11  24.215663         16
76  25.153983         29  25.153983         21
30  20.871625          7  20.871625          9
33  32.627311         17  32.627311         24
11  16.033150         14  16.033150         17
66  30.946841         33  30.946841         33
67  23.152440          9  23.152440          4
31  30.781885         42  30.781885         42
75  35.712116         40  35.712116         33
9   28.836417         27  28.836417         27
68  33.760240         15  33.760240         12
5   30.215128         21  30.215128         20
42  30.535370         28  30.535370         31
47  24.517768         18  24.517768         20
16  31.772067         34  31.772067         31
45  31.798535         22  31.798535         17
34  28.027689         22  28.027689         17
7   32.316638         35  32.316638         35
78  25.668729         21  25.668729         21
27  30.415292         25  30.415292         35
19  27.645700         13  27.645700         16
84  45.666520         41  45.666520         41
25  31.824631         23  31.824631         15
53  33.898364         29  33.898364         29
13  33.162088         10  33.162088         10
24  31.722192         18  31.722192         27
3   20.449996         14  20.449996         15
17  18.477708         10  18.477708         10
38  30.114591         32  30.114591         30
In [89]:
from gurobipy import Model, GRB
from gurobipy import max_

# Define penalties
penalty_pu = 2000000.0000005
penalty_do = 2000000

# Create empty lists to store the results of optimization
optimal_x_values = []
optimal_y_values = []
optimal_objective_values = []

# Loop over the rows in the combined_df DataFrame
for index, row in combined_df.iterrows():
    # Create a new model for each iteration
    m = Model("optimization")

    # Extract the y_pred_pu and y_pred_do values for the current iteration
    y_pred_pu = row['y_pred_pu']
    y_pred_do = row['y_pred_do']

    # Create variables
    x = m.addVar(vtype=GRB.CONTINUOUS, name="x", lb=0)
    y = m.addVar(vtype=GRB.CONTINUOUS, name="y", lb=0)

    # Create auxiliary variables for the max expressions
    max_diff_do = m.addVar(vtype=GRB.CONTINUOUS, name="max_diff_do")
    max_diff_pu = m.addVar(vtype=GRB.CONTINUOUS, name="max_diff_pu")

    # Set objective
    m.setObjective(penalty_do * max_diff_do + penalty_pu * max_diff_pu, GRB.MINIMIZE)

    # Add constraint: x + y = 17 (Example constraint, adjust as needed)
    m.addConstr(x + y == 17, "constraint_sum")
    
    # Add constraints to ensure the auxiliary variables are at least 0 and at least the differences
    m.addConstr(max_diff_do >= 0, "max_diff_do_positive")
    m.addConstr(max_diff_do >= y_pred_do - x, "max_diff_do_y_pred_do")

    m.addConstr(max_diff_pu >= 0, "max_diff_pu_positive")
    m.addConstr(max_diff_pu >= y_pred_pu - y, "max_diff_pu_y_pred_pu")

    # Optimize model
    m.optimize()

    # Store the results
    optimal_x_values.append(x.X)
    optimal_y_values.append(y.X)
    optimal_objective_values.append(m.objVal)

# Add the optimization results to combined_df
combined_df['optimal_x'] = optimal_x_values
combined_df['optimal_y'] = optimal_y_values
combined_df['optimal_objective'] = optimal_objective_values

# Now combined_df includes the optimization results
print(combined_df)
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x79e1675c
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    5.4497081e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  5.449708079e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xa1cb791e
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.4999772e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.499977182e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xf6fcb183
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.5567667e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.556766744e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x15420043
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    5.0274559e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  5.027455908e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x5e9fbd0e
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.0378969e+08   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.037896932e+08
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xd8f54714
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.3671683e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.367168253e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xe4a3263c
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    4.9919196e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  4.991919588e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x47c8575c
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.5476953e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.547695285e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x246df01d
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.1030253e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.103025345e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x2378c6a9
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.7399302e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.739930168e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xf0682018
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    4.0739267e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  4.073926748e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xa83d1ac2
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.0668030e+08   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.066803013e+08
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xec94b01c
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.2799629e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.279962864e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x2d110074
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.2822096e+08   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.282209601e+08
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x70bfe4e4
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    5.4500636e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  5.450063637e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xd8988428
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.7498263e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.749826251e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x265d7eeb
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.2438045e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.243804515e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x92a0598f
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    4.1873201e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  4.187320091e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xe432abcd
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.0961389e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.096138923e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x5bb1f34c
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.0364425e+08   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.036442452e+08
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x6d18b41e
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.9076281e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.907628069e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x602ad6d6
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.2862651e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.286265116e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xceb42e5d
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.6615931e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.661593091e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x1c2e992d
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    4.9486501e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  4.948650132e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x2188e62a
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.6509243e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.650924266e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xcb0d7382
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 3 rows and 1 columns
Presolve time: 0.00s
Presolved: 2 rows, 3 columns, 4 nonzeros

Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    0.0000000e+00   8.016575e+00   0.000000e+00      0s
       2    3.0132599e+07   0.000000e+00   0.000000e+00      0s

Solved in 2 iterations and 0.00 seconds (0.00 work units)
Optimal objective  3.013259891e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xb8894385
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.9787364e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.978736413e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x22223268
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    5.8609761e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  5.860976098e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xaae92695
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.03s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.9127542e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.03 seconds (0.00 work units)
Optimal objective  8.912754162e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xa7f32404
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.0884847e+08   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.088484653e+08
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x2c1e6421
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.1345669e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.134566919e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xcfdab44c
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.0104096e+08   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.010409586e+08
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x18c10255
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.6860513e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.686051254e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x24707421
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.8141478e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.01 seconds (0.00 work units)
Optimal objective  8.814147825e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x16776bf6
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.01s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.4071072e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.01 seconds (0.00 work units)
Optimal objective  6.407107222e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xeafed4fe
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.3088267e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.01 seconds (0.00 work units)
Optimal objective  9.308826697e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x666a9bb6
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.01s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.3194139e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.01 seconds (0.00 work units)
Optimal objective  9.319413899e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x55ee33b0
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.01s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.8110754e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.01 seconds (0.00 work units)
Optimal objective  7.811075416e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x458b7523
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.5266554e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.526655369e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xcd51ec85
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.8674918e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.867491791e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x1b069b95
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.7661166e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.01 seconds (0.00 work units)
Optimal objective  8.766116622e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x1c67aa94
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.6582800e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.658279986e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xdc198a8c
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 5e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.4866608e+08   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.01 seconds (0.00 work units)
Optimal objective  1.486660801e+08
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xaeed9d22
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.3298522e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.329852234e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xa29b858a
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.0159346e+08   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.015934561e+08
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xca0a6eb0
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.8648353e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.864835318e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xf6419013
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.2888766e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.288876650e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x4da8cba6
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    4.7799984e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  4.779998427e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x4192da0e
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    3.9910833e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  3.991083349e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xf6eaf7ee
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.6458365e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.645836515e+07
    y_pred_pu  y_test_pu  y_pred_do  y_test_do  optimal_x  optimal_y  \
40  22.124270         11  22.124270         12   17.00000    0.00000   
22  27.249943         40  27.249943         39   17.00000    0.00000   
55  29.891917         32  29.891917         33   17.00000    0.00000   
70  21.068640         10  21.068640         13   17.00000    0.00000   
0   34.447423         36  34.447423         42   17.00000    0.00000   
26  29.417921         30  29.417921         27   17.00000    0.00000   
39  20.979799          8  20.979799          8   17.00000    0.00000   
65  29.869238         33  29.869238         26   17.00000    0.00000   
10  28.757563         38  28.757563         41   17.00000    0.00000   
44  30.349825         18  30.349825         24   17.00000    0.00000   
81  18.684817          9  18.684817         12   17.00000    0.00000   
35  35.170075         44  35.170075         36   17.00000    0.00000   
56  31.699907         34  31.699907         38   17.00000    0.00000   
86  40.555240         50  40.555240         48   17.00000    0.00000   
12  22.125159         21  22.125159         33   17.00000    0.00000   
4   32.874566         30  32.874566         33   17.00000    0.00000   
18  31.609511         39  31.609511         38   17.00000    0.00000   
28  18.968300         28  18.968300         22   17.00000    0.00000   
49  26.240347         20  26.240347         31   17.00000    0.00000   
62  34.411061         19  34.411061         22   17.00000    0.00000   
73  33.269070         33  33.269070         32   17.00000    0.00000   
69  24.215663         11  24.215663         16   17.00000    0.00000   
76  25.153983         29  25.153983         21   17.00000    0.00000   
30  20.871625          7  20.871625          9   17.00000    0.00000   
33  32.627311         17  32.627311         24   17.00000    0.00000   
11  16.033150         14  16.033150         17    0.96685   16.03315   
66  30.946841         33  30.946841         33   17.00000    0.00000   
67  23.152440          9  23.152440          4   17.00000    0.00000   
31  30.781885         42  30.781885         42   17.00000    0.00000   
75  35.712116         40  35.712116         33   17.00000    0.00000   
9   28.836417         27  28.836417         27   17.00000    0.00000   
68  33.760240         15  33.760240         12   17.00000    0.00000   
5   30.215128         21  30.215128         20   17.00000    0.00000   
42  30.535370         28  30.535370         31   17.00000    0.00000   
47  24.517768         18  24.517768         20   17.00000    0.00000   
16  31.772067         34  31.772067         31   17.00000    0.00000   
45  31.798535         22  31.798535         17   17.00000    0.00000   
34  28.027689         22  28.027689         17   17.00000    0.00000   
7   32.316638         35  32.316638         35   17.00000    0.00000   
78  25.668729         21  25.668729         21   17.00000    0.00000   
27  30.415292         25  30.415292         35   17.00000    0.00000   
19  27.645700         13  27.645700         16   17.00000    0.00000   
84  45.666520         41  45.666520         41   17.00000    0.00000   
25  31.824631         23  31.824631         15   17.00000    0.00000   
53  33.898364         29  33.898364         29   17.00000    0.00000   
13  33.162088         10  33.162088         10   17.00000    0.00000   
24  31.722192         18  31.722192         27   17.00000    0.00000   
3   20.449996         14  20.449996         15   17.00000    0.00000   
17  18.477708         10  18.477708         10   17.00000    0.00000   
38  30.114591         32  30.114591         30   17.00000    0.00000   

    optimal_objective  
40       5.449708e+07  
22       7.499977e+07  
55       8.556767e+07  
70       5.027456e+07  
0        1.037897e+08  
26       8.367168e+07  
39       4.991920e+07  
65       8.547695e+07  
10       8.103025e+07  
44       8.739930e+07  
81       4.073927e+07  
35       1.066803e+08  
56       9.279963e+07  
86       1.282210e+08  
12       5.450064e+07  
4        9.749826e+07  
18       9.243805e+07  
28       4.187320e+07  
49       7.096139e+07  
62       1.036442e+08  
73       9.907628e+07  
69       6.286265e+07  
76       6.661593e+07  
30       4.948650e+07  
33       9.650924e+07  
11       3.013260e+07  
66       8.978736e+07  
67       5.860976e+07  
31       8.912754e+07  
75       1.088485e+08  
9        8.134567e+07  
68       1.010410e+08  
5        8.686051e+07  
42       8.814148e+07  
47       6.407107e+07  
16       9.308827e+07  
45       9.319414e+07  
34       7.811075e+07  
7        9.526655e+07  
78       6.867492e+07  
27       8.766117e+07  
19       7.658280e+07  
84       1.486661e+08  
25       9.329852e+07  
53       1.015935e+08  
13       9.864835e+07  
24       9.288877e+07  
3        4.779998e+07  
17       3.991083e+07  
38       8.645837e+07  
In [90]:
# Define the penalties
penalty_pu = 2000000.0000005
penalty_do = 2000000

# Function to apply the formula
def calculate_penalty(row):
    penalty_for_pu = penalty_pu * max(0, row['y_test_pu'] - row['optimal_y'])
    penalty_for_do = penalty_do * max(0, row['y_test_do'] - row['optimal_x'])
    return penalty_for_pu + penalty_for_do

# Apply the function to each row and create a new column
combined_df['total_out_of_sameple_cost'] = combined_df.apply(calculate_penalty, axis=1)

# Calculate the average of the 'total_penalty' column
average_total_out_of_sameple_cost = combined_df['total_out_of_sameple_cost'].mean()

print("Average Total out of sameple cost:", average_total_out_of_sameple_cost)
Average Total out of sameple cost: 69281325.9890986

Elastic Net - Pickup¶

In [91]:
# Splitting the dataset for training and testing
X = df_merge.drop(columns=['pu_ct'])
y = df_merge['pu_ct']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.6, random_state=200)
In [92]:
from sklearn.linear_model import ElasticNet
from sklearn.linear_model import ElasticNetCV

ENcv = ElasticNetCV(alphas=None, cv=10, max_iter=10000) # default l1_ratio=0.5
ENcv.fit(scale(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']]), y_train)

print('The best alpha from ElasticNetCV:', ENcv.alpha_)
The best alpha from ElasticNetCV: 1.3137665672232992
In [93]:
# with the best alpha
lasso.set_params(alpha=lassocv.alpha_)
lasso.fit(scale(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']]), y_train)


EN=ElasticNet()
EN.set_params(alpha=ENcv.alpha_)
EN.fit(scale(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']]), y_train)

print('The coefficients are:')
print(pd.Series(EN.coef_.flatten(), index=X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']].columns))
The coefficients are:
tempmax         0.487282
tempmin        -0.000000
temp            0.000000
feelslikemax    0.484046
feelslikemin    0.000000
feelslike       0.000000
dew             0.000000
humidity       -0.000000
precip         -1.038672
precipprob     -1.295346
precipcover    -0.997972
snow           -0.000000
windspeed       0.000000
winddir         0.218401
dtype: float64
In [94]:
y_pred = ENcv.predict(scale(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']]))
e_r_p = r2_score(y_test, y_pred)
print(f"R2 in pickup test data for Elastic Net is {e_r_p}")
R2 in pickup test data for Elastic Net is 0.23034166194061512
In [95]:
e_m_p = mean_squared_error(y_test, ENcv.predict(scale(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']])))
print(f"MSE in pickup test data for Elastic Net is {e_m_p}")
MSE in pickup test data for Elastic Net is 87.66322952903276
In [96]:
# Create a DataFrame with predictions and actual outcomes
df_predictions = pd.DataFrame({
    'y_pred_pu': y_pred,
    'y_test_pu': y_test
}).reset_index(drop=True)  # reset_index to ensure we can sample correctly

# Sample 50 random rows from the DataFrame
df_sampled_pu = df_predictions.sample(n=50, random_state=42)  # Use a fixed random state for reproducibility

# df_sampled is now a DataFrame with 50 random rows of predictions and actual values for the specified model
print(df_sampled_pu)
    y_pred_pu  y_test_pu
40  21.606378         11
22  30.089187         40
55  28.392232         32
70  21.700279         10
0   25.761388         36
26  27.274469         30
39  12.974277          8
65  29.714177         33
10  30.103467         38
44  28.941172         18
81  20.534745          9
35  28.560634         44
56  28.764244         34
86  29.982966         50
12  28.297388         21
4   26.032697         30
18  30.166694         39
28  23.989230         28
49  23.324274         20
62  29.615138         19
73  29.219058         33
69  24.528066         11
76  23.794872         29
30  23.145230          7
33  28.303017         17
11  27.045798         14
66  25.331631         33
67  27.216594          9
31  29.555532         42
75  25.749570         40
9   30.001342         27
68  28.687742         15
5   26.341685         21
42  24.616376         28
47  27.914319         18
16  29.350053         34
45  29.362832         22
34  24.319495         22
7   28.860861         35
78  28.290184         21
27  29.266932         25
19  30.409741         13
84  29.737066         41
25  28.425612         23
53  29.077034         29
13  25.492516         10
24  27.847465         18
3   23.559830         14
17  27.118849         10
38  29.318172         32

Elastic Net - Dropoff¶

In [97]:
# Splitting the dataset for training and testing
X = df_merge.drop(columns=['do_ct',])
y = df_merge['do_ct']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.6, random_state=200)
In [98]:
from sklearn.linear_model import ElasticNet
from sklearn.linear_model import ElasticNetCV

ENcv = ElasticNetCV(alphas=None, cv=10, max_iter=10000) # default l1_ratio=0.5
ENcv.fit(scale(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']]), y_train)

print('The best alpha from ElasticNetCV:', ENcv.alpha_)
The best alpha from ElasticNetCV: 0.34106109266715684
In [99]:
# with the best alpha
lasso.set_params(alpha=lassocv.alpha_)
lasso.fit(scale(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']]), y_train)


EN=ElasticNet()
EN.set_params(alpha=ENcv.alpha_)
EN.fit(scale(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']]), y_train)

print('The coefficients are:')
print(pd.Series(EN.coef_.flatten(), index=X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']].columns))
The coefficients are:
tempmax         1.727420
tempmin        -0.482007
temp            0.000000
feelslikemax    0.838336
feelslikemin    0.000000
feelslike       0.876497
dew            -0.000000
humidity       -1.851036
dtype: float64
In [100]:
y_pred = ENcv.predict(scale(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']]))
e_r_d = r2_score(y_test, y_pred)
print(f"R2 in drop off test data for Elastic Net is {e_r_d}")
R2 in drop off test data for Elastic Net is 0.23099600628652295
In [101]:
e_m_d = mean_squared_error(y_test, ENcv.predict(scale(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']])))
print(f"MSE in drop off test data for Elastic Net is {e_m_d}")
MSE in drop off test data for Elastic Net is 84.96981461204777
In [102]:
# Create a DataFrame with predictions and actual outcomes
df_predictions = pd.DataFrame({
    'y_pred_do': y_pred,
    'y_test_do': y_test
}).reset_index(drop=True)  # reset_index to ensure we can sample correctly

# Sample 50 random rows from the DataFrame
df_sampled_do = df_predictions.sample(n=50, random_state=42)  # Use a fixed random state for reproducibility

# df_sampled is now a DataFrame with 50 random rows of predictions and actual values for the specified model
print(df_sampled_do)
    y_pred_do  y_test_do
40  24.641206         12
22  33.634130         39
55  27.392269         33
70  21.713845         13
0   28.052898         42
26  30.465961         27
39  22.747475          8
65  29.919411         26
10  31.681322         41
44  31.606659         24
81  23.292379         12
35  29.824797         36
56  29.165366         38
86  31.712313         48
12  27.284715         33
4   31.061581         33
18  31.528196         38
28  24.631319         22
49  25.207186         31
62  32.314855         22
73  32.274770         32
69  27.234863         16
76  30.878629         21
30  21.338330          9
33  28.813382         24
11  24.247514         17
66  26.427412         33
67  26.332582          4
31  29.645716         42
75  29.544424         33
9   30.695161         27
68  31.539276         12
5   31.580651         20
42  26.293459         31
47  23.679327         20
16  29.182932         31
45  31.024310         17
34  28.209115         17
7   29.843793         35
78  26.499287         21
27  29.391217         35
19  35.015087         16
84  30.128324         41
25  27.931031         15
53  30.346992         29
13  28.329751         10
24  28.186401         27
3   21.495782         15
17  24.493304         10
38  32.288047         30

Decision Performance Evaluation¶

In [103]:
combined_df = df_sampled_pu.join(df_sampled_do, lsuffix='_pu', rsuffix='_do')

# Rename columns as necessary
combined_df.columns = ['y_pred_pu', 'y_test_pu', 'y_pred_do', 'y_test_do']

# Now combined_df has the required columns
print(combined_df)
    y_pred_pu  y_test_pu  y_pred_do  y_test_do
40  21.606378         11  24.641206         12
22  30.089187         40  33.634130         39
55  28.392232         32  27.392269         33
70  21.700279         10  21.713845         13
0   25.761388         36  28.052898         42
26  27.274469         30  30.465961         27
39  12.974277          8  22.747475          8
65  29.714177         33  29.919411         26
10  30.103467         38  31.681322         41
44  28.941172         18  31.606659         24
81  20.534745          9  23.292379         12
35  28.560634         44  29.824797         36
56  28.764244         34  29.165366         38
86  29.982966         50  31.712313         48
12  28.297388         21  27.284715         33
4   26.032697         30  31.061581         33
18  30.166694         39  31.528196         38
28  23.989230         28  24.631319         22
49  23.324274         20  25.207186         31
62  29.615138         19  32.314855         22
73  29.219058         33  32.274770         32
69  24.528066         11  27.234863         16
76  23.794872         29  30.878629         21
30  23.145230          7  21.338330          9
33  28.303017         17  28.813382         24
11  27.045798         14  24.247514         17
66  25.331631         33  26.427412         33
67  27.216594          9  26.332582          4
31  29.555532         42  29.645716         42
75  25.749570         40  29.544424         33
9   30.001342         27  30.695161         27
68  28.687742         15  31.539276         12
5   26.341685         21  31.580651         20
42  24.616376         28  26.293459         31
47  27.914319         18  23.679327         20
16  29.350053         34  29.182932         31
45  29.362832         22  31.024310         17
34  24.319495         22  28.209115         17
7   28.860861         35  29.843793         35
78  28.290184         21  26.499287         21
27  29.266932         25  29.391217         35
19  30.409741         13  35.015087         16
84  29.737066         41  30.128324         41
25  28.425612         23  27.931031         15
53  29.077034         29  30.346992         29
13  25.492516         10  28.329751         10
24  27.847465         18  28.186401         27
3   23.559830         14  21.495782         15
17  27.118849         10  24.493304         10
38  29.318172         32  32.288047         30
In [104]:
from gurobipy import Model, GRB
from gurobipy import max_

# Define penalties
penalty_pu = 2000000.0000005
penalty_do = 2000000

# Create empty lists to store the results of optimization
optimal_x_values = []
optimal_y_values = []
optimal_objective_values = []

# Loop over the rows in the combined_df DataFrame
for index, row in combined_df.iterrows():
    # Create a new model for each iteration
    m = Model("optimization")

    # Extract the y_pred_pu and y_pred_do values for the current iteration
    y_pred_pu = row['y_pred_pu']
    y_pred_do = row['y_pred_do']

    # Create variables
    x = m.addVar(vtype=GRB.CONTINUOUS, name="x", lb=0)
    y = m.addVar(vtype=GRB.CONTINUOUS, name="y", lb=0)

    # Create auxiliary variables for the max expressions
    max_diff_do = m.addVar(vtype=GRB.CONTINUOUS, name="max_diff_do")
    max_diff_pu = m.addVar(vtype=GRB.CONTINUOUS, name="max_diff_pu")

    # Set objective
    m.setObjective(penalty_do * max_diff_do + penalty_pu * max_diff_pu, GRB.MINIMIZE)

    # Add constraint: x + y = 17 (Example constraint, adjust as needed)
    m.addConstr(x + y == 17, "constraint_sum")
    
    # Add constraints to ensure the auxiliary variables are at least 0 and at least the differences
    m.addConstr(max_diff_do >= 0, "max_diff_do_positive")
    m.addConstr(max_diff_do >= y_pred_do - x, "max_diff_do_y_pred_do")

    m.addConstr(max_diff_pu >= 0, "max_diff_pu_positive")
    m.addConstr(max_diff_pu >= y_pred_pu - y, "max_diff_pu_y_pred_pu")

    # Optimize model
    m.optimize()

    # Store the results
    optimal_x_values.append(x.X)
    optimal_y_values.append(y.X)
    optimal_objective_values.append(m.objVal)

# Add the optimization results to combined_df
combined_df['optimal_x'] = optimal_x_values
combined_df['optimal_y'] = optimal_y_values
combined_df['optimal_objective'] = optimal_objective_values

# Now combined_df includes the optimization results
print(combined_df)
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x4e2c2e65
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    5.8495168e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  5.849516813e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x19583f52
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.3446633e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.344663349e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x588d5579
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.7569001e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.756900111e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x109793ad
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    5.2828247e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  5.282824673e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xca482d5c
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.3628572e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.362857229e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x52beaa9e
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.1480859e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.148085854e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xe01837d0
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [1e+01, 2e+01]
Presolve removed 4 rows and 2 columns
Presolve time: 0.00s
Presolved: 1 rows, 2 columns, 2 nonzeros

Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.1494950e+07   6.487139e+00   0.000000e+00      0s
       1    3.7443505e+07   0.000000e+00   0.000000e+00      0s

Solved in 1 iterations and 0.00 seconds (0.00 work units)
Optimal objective  3.744350452e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x2e93909e
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.5267175e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.526717469e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x8eb29559
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.9569578e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.956957781e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x9917e61d
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.7095662e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.709566152e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x5cd22fd3
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    5.3654248e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  5.365424759e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x9057ca83
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.2770861e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.277086108e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x3137a045
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.1859221e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.185922077e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x6886bcda
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.9390559e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.939055882e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x20b4d4a1
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.7164204e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.716420423e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x73c28919
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.0188556e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.018855601e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x0f945be8
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.9389779e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.938977898e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x96912f72
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.3241098e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.324109757e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x175db6f1
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.3062922e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.306292157e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x5010dc90
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.9859986e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.985998568e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x3db161ed
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.8987654e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.898765449e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x428064dd
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.9525857e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.952585657e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x232353c9
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.5347002e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.534700242e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x5479ee50
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    5.4967121e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  5.496712141e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x6482da7f
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.0232797e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.023279738e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x31c38622
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.02s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.8586624e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.02 seconds (0.00 work units)
Optimal objective  6.858662425e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x468a087a
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.9518087e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.951808689e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xa2eda212
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.3098354e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.309835352e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x147e3985
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.4402496e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.440249576e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x94fdde01
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.6587987e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.658798739e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x0210008a
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.7393007e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.739300698e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x86625281
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.6454037e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.645403657e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x8e409921
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.1844672e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.184467193e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xb2c3e1b1
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.7819669e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.781966902e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xb94743dd
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.9187293e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.918729257e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x73039b06
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.3065971e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.306597143e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x2c7e874a
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.6774284e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.677428367e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xa9cb9dcf
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.1057219e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.105721881e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xf580d46e
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.3409308e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.340930789e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x383aa0e2
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.5578943e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.557894288e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xa9a79d0c
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.3316297e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.331629697e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x1c315fa6
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.6849656e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.684965592e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x1c4fe42d
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.5730781e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.573078124e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xcadd1dee
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.8713284e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.871328448e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xf00ea9e8
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.4848051e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.484805116e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xa979f0ed
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.3644534e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.364453408e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x0925fde8
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.8067733e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.806773336e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xa3d04c80
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    5.6111224e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  5.611122370e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xad1b7b94
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.9224306e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.922430625e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xad1934f4
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.9212437e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.921243656e+07
    y_pred_pu  y_test_pu  y_pred_do  y_test_do  optimal_x  optimal_y  \
40  21.606378         11  24.641206         12  17.000000   0.000000   
22  30.089187         40  33.634130         39  17.000000   0.000000   
55  28.392232         32  27.392269         33  17.000000   0.000000   
70  21.700279         10  21.713845         13  17.000000   0.000000   
0   25.761388         36  28.052898         42  17.000000   0.000000   
26  27.274469         30  30.465961         27  17.000000   0.000000   
39  12.974277          8  22.747475          8   4.025723  12.974277   
65  29.714177         33  29.919411         26  17.000000   0.000000   
10  30.103467         38  31.681322         41  17.000000   0.000000   
44  28.941172         18  31.606659         24  17.000000   0.000000   
81  20.534745          9  23.292379         12  17.000000   0.000000   
35  28.560634         44  29.824797         36  17.000000   0.000000   
56  28.764244         34  29.165366         38  17.000000   0.000000   
86  29.982966         50  31.712313         48  17.000000   0.000000   
12  28.297388         21  27.284715         33  17.000000   0.000000   
4   26.032697         30  31.061581         33  17.000000   0.000000   
18  30.166694         39  31.528196         38  17.000000   0.000000   
28  23.989230         28  24.631319         22  17.000000   0.000000   
49  23.324274         20  25.207186         31  17.000000   0.000000   
62  29.615138         19  32.314855         22  17.000000   0.000000   
73  29.219058         33  32.274770         32  17.000000   0.000000   
69  24.528066         11  27.234863         16  17.000000   0.000000   
76  23.794872         29  30.878629         21  17.000000   0.000000   
30  23.145230          7  21.338330          9  17.000000   0.000000   
33  28.303017         17  28.813382         24  17.000000   0.000000   
11  27.045798         14  24.247514         17  17.000000   0.000000   
66  25.331631         33  26.427412         33  17.000000   0.000000   
67  27.216594          9  26.332582          4  17.000000   0.000000   
31  29.555532         42  29.645716         42  17.000000   0.000000   
75  25.749570         40  29.544424         33  17.000000   0.000000   
9   30.001342         27  30.695161         27  17.000000   0.000000   
68  28.687742         15  31.539276         12  17.000000   0.000000   
5   26.341685         21  31.580651         20  17.000000   0.000000   
42  24.616376         28  26.293459         31  17.000000   0.000000   
47  27.914319         18  23.679327         20  17.000000   0.000000   
16  29.350053         34  29.182932         31  17.000000   0.000000   
45  29.362832         22  31.024310         17  17.000000   0.000000   
34  24.319495         22  28.209115         17  17.000000   0.000000   
7   28.860861         35  29.843793         35  17.000000   0.000000   
78  28.290184         21  26.499287         21  17.000000   0.000000   
27  29.266932         25  29.391217         35  17.000000   0.000000   
19  30.409741         13  35.015087         16  17.000000   0.000000   
84  29.737066         41  30.128324         41  17.000000   0.000000   
25  28.425612         23  27.931031         15  17.000000   0.000000   
53  29.077034         29  30.346992         29  17.000000   0.000000   
13  25.492516         10  28.329751         10  17.000000   0.000000   
24  27.847465         18  28.186401         27  17.000000   0.000000   
3   23.559830         14  21.495782         15  17.000000   0.000000   
17  27.118849         10  24.493304         10  17.000000   0.000000   
38  29.318172         32  32.288047         30  17.000000   0.000000   

    optimal_objective  
40       5.849517e+07  
22       9.344663e+07  
55       7.756900e+07  
70       5.282825e+07  
0        7.362857e+07  
26       8.148086e+07  
39       3.744350e+07  
65       8.526717e+07  
10       8.956958e+07  
44       8.709566e+07  
81       5.365425e+07  
35       8.277086e+07  
56       8.185922e+07  
86       8.939056e+07  
12       7.716420e+07  
4        8.018856e+07  
18       8.938978e+07  
28       6.324110e+07  
49       6.306292e+07  
62       8.985999e+07  
73       8.898765e+07  
69       6.952586e+07  
76       7.534700e+07  
30       5.496712e+07  
33       8.023280e+07  
11       6.858662e+07  
66       6.951809e+07  
67       7.309835e+07  
31       8.440250e+07  
75       7.658799e+07  
9        8.739301e+07  
68       8.645404e+07  
5        8.184467e+07  
42       6.781967e+07  
47       6.918729e+07  
16       8.306597e+07  
45       8.677428e+07  
34       7.105722e+07  
7        8.340931e+07  
78       7.557894e+07  
27       8.331630e+07  
19       9.684966e+07  
84       8.573078e+07  
25       7.871328e+07  
53       8.484805e+07  
13       7.364453e+07  
24       7.806773e+07  
3        5.611122e+07  
17       6.922431e+07  
38       8.921244e+07  
In [105]:
# Define the penalties
penalty_pu = 2000000.0000005
penalty_do = 2000000

# Function to apply the formula
def calculate_penalty(row):
    penalty_for_pu = penalty_pu * max(0, row['y_test_pu'] - row['optimal_y'])
    penalty_for_do = penalty_do * max(0, row['y_test_do'] - row['optimal_x'])
    return penalty_for_pu + penalty_for_do

# Apply the function to each row and create a new column
combined_df['total_out_of_sameple_cost'] = combined_df.apply(calculate_penalty, axis=1)

# Calculate the average of the 'total_penalty' column
average_total_out_of_sameple_cost = combined_df['total_out_of_sameple_cost'].mean()

print("Average Total out of sameple cost:", average_total_out_of_sameple_cost)
Average Total out of sameple cost: 69038971.09066798

KNN - Pickup¶

In [106]:
# Splitting the dataset for training and testing
X = df_merge.drop(columns=['pu_ct'])
y = df_merge['pu_ct']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.6, random_state=200)
In [107]:
from sklearn import neighbors
from sklearn.metrics import mean_squared_error
import matplotlib.pyplot as plt
In [108]:
model = neighbors.KNeighborsRegressor(n_neighbors = 15)
model.fit(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']], y_train)
Out[108]:
KNeighborsRegressor(n_neighbors=15)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
KNeighborsRegressor(n_neighbors=15)
In [109]:
# Testing MSE
k_m_p = mean_squared_error(y_test, model.predict(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']]))
print(f"MSE in pickup test data for KNN is {k_m_p}")
MSE in pickup test data for KNN is 95.0970864197531
In [110]:
# Test R2
k_r_p = r2_score(y_test, model.predict(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']]))
print(f"R2 in pickup testing data for KNN is {k_r_p}")
R2 in pickup testing data for KNN is 0.1650745029433729
In [111]:
# Tranining MSE
k_m_tr_p = mean_squared_error(y_train, model.predict(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']]))
print(f"MSE in pickup training data for KNN is {k_m_tr_p}")
MSE in pickup training data for KNN is 81.44970370370372
In [112]:
k_m_tr_p = [-1]*30
k_m_p = [-1]*30
for K in range(30):
    model = neighbors.KNeighborsRegressor(n_neighbors = K+1)
    model.fit(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']], y_train)  #fit the model
    k_m_tr_p[K] = mean_squared_error(y_train, model.predict(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']]))
    k_m_p[K] = mean_squared_error(y_test, model.predict(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']]))
In [113]:
import matplotlib.pyplot as plt
fig, ax1 = plt.subplots(figsize=(12, 9))
plt.plot(np.arange(30)+1, k_m_tr_p,  color = 'blue', marker = '.', markersize = 8, markeredgecolor = 'black', markerfacecolor = 'black',label = 'mse_train_pu')
plt.plot(np.arange(30)+1, k_m_p,  color = 'red',marker = '.', markersize = 8, markeredgecolor = 'black', markerfacecolor = 'black', label = 'mse_test_pu')
plt.legend(fontsize=18)
plt.title('MSE with different Ks', fontsize=22)
plt.tick_params(labelsize=18)
plt.show()
No description has been provided for this image
In [114]:
np.argmin(k_m_p)+1
Out[114]:
3
In [115]:
model = neighbors.KNeighborsRegressor(n_neighbors = 4)
model.fit(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']], y_train)
Out[115]:
KNeighborsRegressor(n_neighbors=4)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
KNeighborsRegressor(n_neighbors=4)
In [116]:
y_pred = model.predict(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity', 'precip', 'precipprob', 'precipcover', 'snow', 'windspeed', 'winddir']])
In [117]:
# Create a DataFrame with predictions and actual outcomes
df_predictions = pd.DataFrame({
    'y_pred_pu': y_pred,
    'y_test_pu': y_test
}).reset_index(drop=True)  # reset_index to ensure we can sample correctly

# Sample 50 random rows from the DataFrame
df_sampled_pu = df_predictions.sample(n=50, random_state=42)  # Use a fixed random state for reproducibility

# df_sampled is now a DataFrame with 50 random rows of predictions and actual values for the specified model
print(df_sampled_pu)
    y_pred_pu  y_test_pu
40      19.50         11
22      29.50         40
55      38.25         32
70      18.75         10
0       18.75         36
26      22.50         30
39      15.50          8
65      29.50         33
10      32.50         38
44      26.25         18
81      16.75          9
35      37.50         44
56      35.50         34
86      34.50         50
12      30.00         21
4       22.50         30
18      30.50         39
28      14.75         28
49      20.25         20
62      23.75         19
73      38.75         33
69      16.00         11
76      26.25         29
30      21.25          7
33      32.25         17
11      22.75         14
66      22.50         33
67      22.75          9
31      35.25         42
75      22.50         40
9       33.75         27
68      36.50         15
5       22.50         21
42      15.25         28
47      29.50         18
16      35.50         34
45      24.00         22
34      20.25         22
7       31.50         35
78      30.00         21
27      40.50         25
19      30.25         13
84      35.25         41
25      34.00         23
53      26.25         29
13      26.25         10
24      32.25         18
3       21.25         14
17      22.75         10
38      26.25         32

KNN - Dropoff¶

In [118]:
# Splitting the dataset for training and testing
X = df_merge.drop(columns=['do_ct',])
y = df_merge['do_ct']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.6, random_state=200)
In [119]:
from sklearn import neighbors
from sklearn.metrics import mean_squared_error
import matplotlib.pyplot as plt

model = neighbors.KNeighborsRegressor(n_neighbors = 15)
model.fit(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']], y_train)
Out[119]:
KNeighborsRegressor(n_neighbors=15)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
KNeighborsRegressor(n_neighbors=15)
In [120]:
# Testing MSE
k_m_d = mean_squared_error(y_test, model.predict(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']]))
print(f"MSE in drop off test data for KNN is {k_m_d}")
MSE in drop off test data for KNN is 99.83150617283951
In [121]:
# Test R2
k_r_d = r2_score(y_test, model.predict(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']]))
print(f"R2 in drop off testing data for KNN is {k_r_d}")
R2 in drop off testing data for KNN is 0.09649294521986673
In [122]:
# Tranining MSE
k_m_tr_d = mean_squared_error(y_train, model.predict(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']]))
print(f"MSE in drop off training data for KNN is {k_m_tr_d}")
MSE in drop off training data for KNN is 91.53451851851852
In [123]:
k_m_tr_d = [-1]*30
k_m_d = [-1]*30
for K in range(30):
    model = neighbors.KNeighborsRegressor(n_neighbors = K+1)
    model.fit(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']], y_train)  #fit the model
    k_m_tr_d[K] = mean_squared_error(y_train, model.predict(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']]))
    k_m_d[K] = mean_squared_error(y_test, model.predict(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']]))
In [124]:
import matplotlib.pyplot as plt
fig, ax1 = plt.subplots(figsize=(12, 9))
plt.plot(np.arange(30)+1, k_m_tr_d,  color = 'blue', marker = '.', markersize = 8, markeredgecolor = 'black', markerfacecolor = 'black',label = 'mse_train_do')
plt.plot(np.arange(30)+1, k_m_d,  color = 'red',marker = '.', markersize = 8, markeredgecolor = 'black', markerfacecolor = 'black', label = 'mse_test_do')
plt.legend(fontsize=18)
plt.title('MSE with different Ks', fontsize=22)
plt.tick_params(labelsize=18)
plt.show()
No description has been provided for this image
In [125]:
np.argmin(k_m_p)+1
Out[125]:
3
In [126]:
model = neighbors.KNeighborsRegressor(n_neighbors = 4)
model.fit(X_train[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']], y_train)
y_pred = model.predict(X_test[['tempmax', 'tempmin', 'temp', 'feelslikemax', 'feelslikemin', 'feelslike', 'dew', 'humidity']])
In [127]:
# Create a DataFrame with predictions and actual outcomes
df_predictions = pd.DataFrame({
    'y_pred_do': y_pred,
    'y_test_do': y_test
}).reset_index(drop=True)  # reset_index to ensure we can sample correctly

# Sample 50 random rows from the DataFrame
df_sampled_do = df_predictions.sample(n=50, random_state=42)  # Use a fixed random state for reproducibility

# df_sampled is now a DataFrame with 50 random rows of predictions and actual values for the specified model
print(df_sampled_do)
    y_pred_do  y_test_do
40      31.25         12
22      30.75         39
55      26.75         33
70      17.75         13
0       29.75         42
26      36.25         27
39      23.50          8
65      41.25         26
10      35.00         41
44      23.25         24
81      20.75         12
35      26.25         36
56      38.50         38
86      42.25         48
12      31.25         33
4       22.75         33
18      36.25         38
28      26.50         22
49      31.00         31
62      39.25         22
73      22.75         32
69      20.00         16
76      26.50         21
30      22.25          9
33      23.50         24
11      17.75         17
66      30.50         33
67      22.75          4
31      39.50         42
75      37.75         33
9       36.25         27
68      29.50         12
5       30.00         20
42      25.25         31
47      20.75         20
16      32.50         31
45      27.50         17
34      31.25         17
7       29.00         35
78      22.50         21
27      31.25         35
19      29.00         16
84      32.25         41
25      27.75         15
53      33.75         29
13      33.50         10
24      21.00         27
3       22.25         15
17      22.75         10
38      26.75         30

Decision Performance Evaluation¶

In [128]:
combined_df = df_sampled_pu.join(df_sampled_do, lsuffix='_pu', rsuffix='_do')

# Rename columns as necessary
combined_df.columns = ['y_pred_pu', 'y_test_pu', 'y_pred_do', 'y_test_do']

# Now combined_df has the required columns
print(combined_df)
    y_pred_pu  y_test_pu  y_pred_do  y_test_do
40      19.50         11      31.25         12
22      29.50         40      30.75         39
55      38.25         32      26.75         33
70      18.75         10      17.75         13
0       18.75         36      29.75         42
26      22.50         30      36.25         27
39      15.50          8      23.50          8
65      29.50         33      41.25         26
10      32.50         38      35.00         41
44      26.25         18      23.25         24
81      16.75          9      20.75         12
35      37.50         44      26.25         36
56      35.50         34      38.50         38
86      34.50         50      42.25         48
12      30.00         21      31.25         33
4       22.50         30      22.75         33
18      30.50         39      36.25         38
28      14.75         28      26.50         22
49      20.25         20      31.00         31
62      23.75         19      39.25         22
73      38.75         33      22.75         32
69      16.00         11      20.00         16
76      26.25         29      26.50         21
30      21.25          7      22.25          9
33      32.25         17      23.50         24
11      22.75         14      17.75         17
66      22.50         33      30.50         33
67      22.75          9      22.75          4
31      35.25         42      39.50         42
75      22.50         40      37.75         33
9       33.75         27      36.25         27
68      36.50         15      29.50         12
5       22.50         21      30.00         20
42      15.25         28      25.25         31
47      29.50         18      20.75         20
16      35.50         34      32.50         31
45      24.00         22      27.50         17
34      20.25         22      31.25         17
7       31.50         35      29.00         35
78      30.00         21      22.50         21
27      40.50         25      31.25         35
19      30.25         13      29.00         16
84      35.25         41      32.25         41
25      34.00         23      27.75         15
53      26.25         29      33.75         29
13      26.25         10      33.50         10
24      32.25         18      21.00         27
3       21.25         14      22.25         15
17      22.75         10      22.75         10
38      26.25         32      26.75         30
In [ ]:
from gurobipy import Model, GRB
from gurobipy import max_

# Define penalties
penalty_pu = 2000000.0000005
penalty_do = 2000000

# Create empty lists to store the results of optimization
optimal_x_values = []
optimal_y_values = []
optimal_objective_values = []

# Loop over the rows in the combined_df DataFrame
for index, row in combined_df.iterrows():
    # Create a new model for each iteration
    m = Model("optimization")

    # Extract the y_pred_pu and y_pred_do values for the current iteration
    y_pred_pu = row['y_pred_pu']
    y_pred_do = row['y_pred_do']

    # Create variables
    x = m.addVar(vtype=GRB.CONTINUOUS, name="x", lb=0)
    y = m.addVar(vtype=GRB.CONTINUOUS, name="y", lb=0)

    # Create auxiliary variables for the max expressions
    max_diff_do = m.addVar(vtype=GRB.CONTINUOUS, name="max_diff_do")
    max_diff_pu = m.addVar(vtype=GRB.CONTINUOUS, name="max_diff_pu")

    # Set objective
    m.setObjective(penalty_do * max_diff_do + penalty_pu * max_diff_pu, GRB.MINIMIZE)

    # Add constraint: x + y = 17 (Example constraint, adjust as needed)
    m.addConstr(x + y == 17, "constraint_sum")
    
    # Add constraints to ensure the auxiliary variables are at least 0 and at least the differences
    m.addConstr(max_diff_do >= 0, "max_diff_do_positive")
    m.addConstr(max_diff_do >= y_pred_do - x, "max_diff_do_y_pred_do")

    m.addConstr(max_diff_pu >= 0, "max_diff_pu_positive")
    m.addConstr(max_diff_pu >= y_pred_pu - y, "max_diff_pu_y_pred_pu")

    # Optimize model
    m.optimize()

    # Store the results
    optimal_x_values.append(x.X)
    optimal_y_values.append(y.X)
    optimal_objective_values.append(m.objVal)

# Add the optimization results to combined_df
combined_df['optimal_x'] = optimal_x_values
combined_df['optimal_y'] = optimal_y_values
combined_df['optimal_objective'] = optimal_objective_values

# Now combined_df includes the optimization results
print(combined_df)
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xd302ed30
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.7500000e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.750000000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x249c815a
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.6500000e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.650000000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xd8024e50
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.6000000e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.600000000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xa3edbc22
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    3.9000000e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  3.900000000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x932be9e4
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.3000000e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.300000000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xd7b71b4e
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.3500000e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.350000000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x2ffc1a1a
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 4 rows and 2 columns
Presolve time: 0.00s
Presolved: 1 rows, 2 columns, 2 nonzeros

Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.3000000e+07   7.750000e+00   0.000000e+00      0s
       1    4.4000000e+07   0.000000e+00   0.000000e+00      0s

Solved in 1 iterations and 0.00 seconds (0.00 work units)
Optimal objective  4.400000000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xb4f103d3
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.0750000e+08   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.075000000e+08
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x26a9e55a
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.0100000e+08   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.010000000e+08
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xb3425350
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.5000000e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.500000000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xbd1cbb17
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 4 rows and 2 columns
Presolve time: 0.00s
Presolved: 1 rows, 2 columns, 2 nonzeros

Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.5000000e+06   8.375000e+00   0.000000e+00      0s
       1    4.1000000e+07   0.000000e+00   0.000000e+00      0s

Solved in 1 iterations and 0.00 seconds (0.00 work units)
Optimal objective  4.100000000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x3c849f9b
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.3500000e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.350000000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xbb5a2ed7
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.1400000e+08   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.140000000e+08
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x456c1143
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.1950000e+08   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  1.195000000e+08
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x69c2155f
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.8500000e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.850000000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x51f1d587
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    5.6500000e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  5.650000000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x4900bda0
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.9500000e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.950000000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x2de5d89d
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [1e+01, 3e+01]
Presolve removed 4 rows and 2 columns
Presolve time: 0.00s
Presolved: 1 rows, 2 columns, 2 nonzeros

Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.9000000e+07   7.375000e+00   0.000000e+00      0s
       1    4.8500000e+07   0.000000e+00   0.000000e+00      0s

Solved in 1 iterations and 0.00 seconds (0.00 work units)
Optimal objective  4.850000000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x41c09d36
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.8500000e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  6.850000000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x8d2cb1ac
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    9.2000000e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  9.200000000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x3a737b55
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 4e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    8.9000000e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  8.900000000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x4594507a
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 2e+01]
Presolve removed 4 rows and 2 columns
Presolve time: 0.00s
Presolved: 1 rows, 2 columns, 2 nonzeros

Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    6.0000000e+06   8.000000e+00   0.000000e+00      0s
       1    3.8000000e+07   0.000000e+00   0.000000e+00      0s

Solved in 1 iterations and 0.00 seconds (0.00 work units)
Optimal objective  3.800000000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xd4abb88e
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+06, 2e+06]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+01, 3e+01]
Presolve removed 5 rows and 4 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    7.1500000e+07   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  7.150000000e+07
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.0.0 23A344)

CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 5 rows, 4 columns and 8 nonzeros
Model fingerprint: 0xb986af4e
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
In [ ]:
# Define the penalties
penalty_pu = 2000000.0000005
penalty_do = 2000000

# Function to apply the formula
def calculate_penalty(row):
    penalty_for_pu = penalty_pu * max(0, row['y_test_pu'] - row['optimal_y'])
    penalty_for_do = penalty_do * max(0, row['y_test_do'] - row['optimal_x'])
    return penalty_for_pu + penalty_for_do

# Apply the function to each row and create a new column
combined_df['total_out_of_sameple_cost'] = combined_df.apply(calculate_penalty, axis=1)

# Calculate the average of the 'total_penalty' column
average_total_out_of_sameple_cost = combined_df['total_out_of_sameple_cost'].mean()

print("Average Total out of sameple cost:", average_total_out_of_sameple_cost)

Conclusion¶

Based on the Average Total out of sameple cost, We decided that the Linear regression model is the best model among 4 with the least Average Total out of sameple cost of 68153491.96792553 given penalty_pu = 2000000.0000005 and penalty_do = 2000000